msgpack-swift

2.0.1

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

What's New

2023-12-22T21:49:50Z

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

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

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!

Usage

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)

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Thu Mar 21 2024 21:28:18 GMT-0900 (Hawaii-Aleutian Daylight Time)