MessagePack
为 Codable
类型提供 MessagePack 编码器和解码器。
此功能在 Flight School Swift Codable 指南的第 7 章中讨论。
MessagePackEncoder
let encoder = MessagePackEncoder()
let value = try! encoder.encode(["a": 1, "b": 2, "c": 3])
// [0x83, 0xA1, 0x62, 0x02, 0xA1, 0x61, 0x01, 0xA1, 0x63, 0x03]
MessagePackDecoder
let decoder = MessagePackDecoder()
let data = Data(bytes: [0xCB, 0x40, 0x09, 0x21, 0xF9, 0xF0, 0x1B, 0x86, 0x6E])
let value = try! decoder.decode(Double.self, from: data)
// 3.14159
许可证
MIT
联系方式
Mattt (@mattt)