Get Updates By E-mail 

Article Written By:
Johann Dowa

SwiftMsgPack – Swift Library For Easily Working With The Binary MsgPack Object Serialization Format

  •  
  •  
  •  
  •  
  •  

SwiftMsgPack is an open source library Swift based library submitted by Daniele Margutti for object serialization using MsgPack.

MsgPack is an efficient binary-based serialization library that is faster and more efficient than JSON because of its compact binary format. This can result in dramatic bandwidth savings, and MsgPack is already supported by over 50 languages.

SwiftMsgPack provides a simple syntax for both object serialization and de-serialization:

This snippet from the readme shows how to serialize and de-serialize using SwiftMsgPack:

var data = Data()
do {
    let obj1 = "Hello World"
    let obj2 = 45.5
    let obj3: [AnyHashable:Any?] = [ "key_1" : "value test","key_2" : 4,"key_3" : true, otherHashableKey: "value1"]
    // Now you can pack your instances by passing them to pack function
    try data.pack(obj1,obj2,obj3)
} catch {
    print("Something went wrong while packing data: &#40;error)")<br />
}

let data: Data = // msgpack data...
do {
  let decodedObj: Any? = try data.unpack()
} catch {
    print("Something went wrong while unpacking data: &#40;error)")<br />
}

You can find SwiftMsgPack on Github here.

A useful library for object serialization/deserialization.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments