Swiftpack.co - Package - hirotakan/MessagePacker

MessagePacker

Build Status Swift 5.0 License Carthage compatible Cocoapods SwiftPM Platforms

MessagePacker is a MessagePack encoder & decoder for Swift and supports Codable.

  • Message Pack specification: https://github.com/msgpack/msgpack/blob/master/spec.md

Usage

import MessagePacker

struct Coordinate: Codable {
    var latitude: Double
    var longitude: Double
}

struct Landmark: Codable {
    var name: String
    var foundingYear: Int
    var location: Coordinate
}

let input = Landmark(
    name: "Mojave Desert",
    foundingYear: 0,
    location: Coordinate(
        latitude: 35.0110079,
        longitude: -115.4821313
    )
)

let data = try! MessagePackEncoder().encode(input)
let landmark = try! MessagePackDecoder().decode(Landmark.self, from: data)

print([UInt8](https://raw.github.com/hirotakan/MessagePacker/blob/master/data))
print(landmark)

// [131, 164, 110, 97, 109, 101, 173, 77, 111, 106,
//  97, 118, 101, 32, 68, 101, 115, 101, 114, 116,
//  172, 102, 111, 117, 110, 100, 105, 110, 103, 89,
//  101, 97, 114, 0, 168, 108, 111, 99, 97, 116,
//  105, 111, 110, 130, 168, 108, 97, 116, 105, 116,
//  117, 100, 101, 203, 64, 65, 129, 104, 180, 245,
//  63, 179, 169, 108, 111, 110, 103, 105, 116, 117,
//  100, 101, 203, 192, 92, 222, 219, 61, 61, 120, 49]

// Landmark(
//     name: "Mojave Desert",
//     foundingYear: 0,
//     location: MessagePackerTests.Coordinate(
//         latitude: 35.0110079,
//         longitude: -115.4821313
//     )
// )

Installation

Carthage

Add the following to your Cartfile:

github "hirotakan/MessagePacker"

CocoaPods

Add the following to your Podfile:

pod 'MessagePacker'

SwiftPM

Add MessagePacker as a dependency:

import PackageDescription

let package = Package(
    name: "YourApp",
    dependencies: [
        .Package(url: "https://github.com/hirotakan/MessagePacker.git", majorVersion: 0),
    ]
)

Requirements

  • Swift 5.0 or later
  • iOS 8.0 or later
  • macOS 10.10 or later
  • tvOS 9.0 or later
  • watchOS 2.0 or later

License

MessagePacker is released under the MIT license. See LICENSE for details.

Github

link
Stars: 37

Dependencies

Used By

Total: 0

Releases

0.4.3 - 2020-08-31 11:36:24

  • Fix Package.swift (https://github.com/hirotakan/MessagePacker/pull/34)
  • Fix to be able to decode empty strings (https://github.com/hirotakan/MessagePacker/pull/35)
  • Use Github Actions (https://github.com/hirotakan/MessagePacker/pull/36)

0.4.2 - 2020-08-25 03:05:01

Fix bytes limit of "fixstr" (https://github.com/hirotakan/MessagePacker/pull/32)

0.4.1 - 2019-09-14 06:12:28

  • Fixed map encoding (https://github.com/hirotakan/MessagePacker/pull/26)

0.4.0 - 2019-04-13 12:49:16

  • Support Swift 5.0 (https://github.com/hirotakan/MessagePacker/pull/23)

0.3.3 - 2019-04-13 07:46:21

  • Added osx, watchos, tvos target to podspec (https://github.com/hirotakan/MessagePacker/pull/21)

0.3.2 - 2019-03-16 01:59:53

  • Improve performance (https://github.com/hirotakan/MessagePacker/pull/16)

0.3.1 - 2019-03-10 04:17:13

  • Bug fix in decoded logic of signed integer.

0.3.0 - 2019-02-24 02:45:36

  • Support Swift Package Manager.
  • Unsupport Swift 4.0.

0.2.0 - 2019-01-06 07:49:29

  • Supports watchOS
  • Supports tvOS
  • Supports macOS

0.1.0 - 2018-12-28 07:09:35

  • Supports Xcode 9
  • Supports 32 bit devices
  • Add travis ci

0.0.1 - 2018-12-28 06:13:08

Initial release 🎉