Skip to content

An efficient, full-featured, and compliant MessagePack implementation for Swift. / msgpack.org[Swift]

License

Notifications You must be signed in to change notification settings

fumoboy007/msgpack-swift

Repository files navigation

msgpack-swift

An efficient, full-featured, and compliant MessagePack implementation for Swift.

Swift 5.9 Linux, visionOS 1, macOS 13, iOS 16, tvOS 16, watchOS 9 MIT License Automated Tests Workflow Status

Basic Usage

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.

Features

  • Full integration with Swift’s Codable serialization system.
  • Support for standard Foundation value types such as Date, URL, Data, and Decimal.
  • 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.

Compared to the Competition

(As of September 2023.)

Functionality

Other Library Remarks
nnabeyang/swift-msgpack ⚠️ No tailored support for Date, URL, or Decimal.
hirotakan/MessagePacker ⚠️ Does not support complex nested container setups.
⚠️ Missing some validation logic.
⚠️ No tailored support for Decimal.
Flight-School/MessagePack ⚠️ Does not support complex nested container setups.
⚠️ Does not have a timestamp type to preserve precision.
⚠️ No tailored support for URL or Decimal.
⚠️ Does not support application-specific MessagePack extension types.
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.

Performance

Speed Compared to Other Library
Up to 3× faster than nnabeyang/swift-msgpack
Up to 2× faster than hirotakan/MessagePacker
Up to 6× faster than Flight-School/MessagePack

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!