Netstrings in Swift
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Netstring.xcodeproj
Netstring Report streamEnded if first read returns 0 bytes Jun 18, 2017
NetstringTests
Usage.playground
.gitignore Add docsets to ignore May 21, 2017
.travis.yml Add .travis.yml May 21, 2017
LICENSE
README.md Add documentation badge May 21, 2017

README.md

Netstrings in Swift

Build Status Documentation Status

Implements netstrings in Swift 3.1.

Usage

To create a netstring:

let ns = Netstring(payload: [0x4f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x20, 0x4d, 0x65, 0x6e, 0x61, 0x63, 0x65])
let bytes = ns.export()

To parse:

let data: [UInt8] = [0x34, 0x3a, 0x73, 0x77, 0x61, 0x67, 0x2c]
if case let .success(ns) = Netstring.parse(array: data) {
    let payload = ns.payload
}

The array-based constructor delegates to a closure-based one. It takes in a closure of type (Int) -> [UInt8] that Netstring asks to provide bytes as necessary. You can use it to read input from a stream (socket, pipe, file etc.)

See also the reference documentation, Usage.playground and NetstringTests.