Latest 1.0.0
Homepage https://github.com/echlo/hummingbird-swift
License MIT
Platforms ios 8.0
Authors

Hummingbird-Swift

This is an implementation of the Hummingbird parser and serializer for Swift.

Synopsis

Hummingbird is a binary serialization format. See the spec
for details and format specification.

Installing

Cocoapods

CocoaPods is a dependency manager for Cocoa projects.
You can install it with the following command:

$ gem install cocoapods

To integrate Hummingbird into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Hummingbird', :git => 'https://github.com/echlo/hummingbird-swift'
end

Then, run the following command:

$ pod install

Import Hummingbird at the top of any file that needs to call the framework

import Hummingbird

Demo

Here’s an online converter

Usage

Hummingbird can be used to serialize Swift classes or structs into HBON. This
works best if the class or struct extends HBEncodable and HBDecodable and
provide custom implementations for serializing or rehydrating the object.

struct Event: HBEncodable, HBDecodable {
    let timestamp: Double
    let level: Double

    init(timestamp: Double, level: Double) {
        self.timestamp = timestamp
        self.level = level
    }

    init(decoder: HBDecoder) throws {
        timestamp = (try? decoder.decode("timestamp")) ?? -1
        level = (try? decoder.decode("level")) ?? 0.0
    }

    func encode(_ encoder: HBEncoder) {
        encoder.encode(timestamp, forKey: "timestamp")
        encoder.encode(level, forKey: "level")
    }
}

Then simple call the serialize and deserialize methods

do {
    let eventBytes = try HummingBird.serialize(event)    
} catch {
    // handle serialization error
}

do {
    response: Event = try HummingBird.deserialize(eventBytes)
} catch {
    // handle deserialization error
}

Non-object serialization and deserialization

This library provides simple methods to serialize and deserialize variables that
are not classes or structs.

do {
    let data: [UInt8] = try HummingBird.serializeAsRoot(stringVariable)            
} catch {
    // handle serialization error
}

do {
    let stringVar: string = try HummingBird.deserializeAsRoot(data)    
} catch {
    // handle deserialization error
}

(More comprehensive documentation TBD)

Tests

This project includes XCTestCases

Contributors

Current maintainer

License

This project is licensed under the MIT License – see the LICENSE file for details

Latest podspec

{
    "name": "Hummingbird",
    "version": "1.0.0",
    "summary": "This is a Swift implementation of the parser and serializer for HummingBird Object Notation.",
    "homepage": "https://github.com/echlo/hummingbird-swift",
    "license": "MIT",
    "authors": {
        "Echlo, Inc": "[email protected]"
    },
    "source": {
        "git": "https://github.com/echlo/Hummingbird-swift.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Hummingbird/*.swift",
    "pushed_with_swift_version": "3.1"
}

Pin It on Pinterest

Share This