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:
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: (error)")<br />
}
let data: Data = // msgpack data…
do {
let decodedObj: Any? = try data.unpack()
} catch {
print("Something went wrong while unpacking data: (error)")<br />
}
You can find SwiftMsgPack on Github here.
A useful library for object serialization/deserialization.
Original article: SwiftMsgPack – Swift Library For Easily Working With The Binary MsgPack Object Serialization Format
©2017 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.
Reference source: iOS App Dev Libraries, Controls, Tutorials, Examples and Tools