An efficient, full-featured, and compliant MessagePack implementation for Swift.
import MessagePack
struct MyMessage: Codable {
// ...
}
let myMessage = MyMessage(
// ...
)
// Serialization
let encoder = MessagePackEncoder()
let serializedMessage = try encoder.encode(myMessage)
// Deserialization
let decoder = MessagePackDecoder()
let deserializedMessage = try decoder.decode(MyMessage.self, from: serializedMessage)
See the documentation for examples of more advanced use cases.
- Full integration with Swift’s
Codable
serialization system. - Support for standard
Foundation
value types such asDate
,URL
,Data
, andDecimal
. - Support for MessagePack extension types like timestamp and application-specific extension types.
- Automated tests verify compliance with the MessagePack specification by testing against the
msgpack-c
reference implementation. - Highly optimized for performance.
(As of September 2023.)
Other Library | Remarks |
---|---|
nnabeyang/swift-msgpack |
Date , URL , or Decimal . |
hirotakan/MessagePacker |
Decimal . |
Flight-School/MessagePack |
URL or Decimal . |
swiftstack/messagepack |
❌ Timestamp type is not Codable . |
malcommac/SwiftMsgPack |
❌ Does not support Codable . |
a2/MessagePack.swift |
❌ Does not support Codable . |
michael-yuji/YSMessagePack |
❌ Does not support Codable . |
briandw/SwiftPack |
❌ Does not have a Swift package manifest. |
Other Library | Compared to This Library |
---|---|
nnabeyang/swift-msgpack |
Up to 3× slower. |
hirotakan/MessagePacker |
Up to 2× slower. |
Flight-School/MessagePack |
Up to 6× slower. |
Tested using real-world messages that are involved in high throughput or low latency use cases. Pull requests to Benchmarks.swift
are welcome if you know of similar use cases!