An efficient, full-featured, and compliant MessagePack implementation for Swift.
- 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!
Below is a basic example. See the documentation for more details.
import MessagePack
struct MyMessage: Codable {
let myBool: Bool
let myOptionalDecimal: Decimal?
let myStringArray: [String]
let myTimestamp: MessagePackTimestamp
}
let myMessage = MyMessage(
myBool: true,
myOptionalDecimal: nil,
myStringArray: ["hello", "world"],
myTimestamp: MessagePackTimestamp(internetDateTime: "2023-09-10T19:19:59.123456789-07:00")!
)
let encoder = MessagePackEncoder()
let myMessageBytes = try encoder.encode(myMessage)
let decoder = MessagePackDecoder()
let myMessageDecoded = try decoder.decode(MyMessage.self, from: myMessageBytes)