Contents

fumoboy007/msgpack-swift

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

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.<br />⚠️ Missing some validation logic.<br />⚠️ No tailored support for Decimal. | | Flight-School/MessagePack | ⚠️ Does not support complex nested container setups.<br />⚠️ Does not have a timestamp type to preserve precision.<br />⚠️ No tailored support for URL or Decimal.<br />⚠️ 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!

Package Metadata

Repository: fumoboy007/msgpack-swift

Default branch: main

README: README.md