Skip to content

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Feb 26, 2019
2 parents 3a38a02 + c96cb07 commit 76b509f
Show file tree
Hide file tree
Showing 27 changed files with 1,685 additions and 116 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.build
/Packages
/*.xcodeproj
bin/protoc
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ matrix:
os: osx
osx_image: xcode10.1
language: swift
before_script:
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-osx-x86_64.zip
- unzip protoc-3.6.1-osx-x86_64.zip
script:
- swift test

Expand All @@ -20,6 +23,8 @@ matrix:
dist: xenial
language: c
before_script:
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip
- unzip protoc-3.6.1-linux-x86_64.zip
- wget https://swift.org/builds/swift-4.2.2-release/ubuntu1604/swift-4.2.2-RELEASE/swift-4.2.2-RELEASE-ubuntu16.04.tar.gz
- tar xzf swift-4.2.2-RELEASE-ubuntu16.04.tar.gz
- export PATH=$(pwd)/swift-4.2.2-RELEASE-ubuntu16.04/usr/bin:"${PATH}"
Expand All @@ -32,9 +37,11 @@ matrix:
dist: xenial
language: c
before_script:
- wget "https://swift.org/builds/development/ubuntu1604/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-ubuntu16.04.tar.gz"
- tar xzf swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-ubuntu16.04.tar.gz
- export PATH=$(pwd)/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-ubuntu16.04/usr/bin:"${PATH}"
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip
- unzip protoc-3.6.1-linux-x86_64.zip
- wget "https://swift.org/builds/development/ubuntu1604/swift-DEVELOPMENT-SNAPSHOT-2019-02-19-a/swift-DEVELOPMENT-SNAPSHOT-2019-02-19-a-ubuntu16.04.tar.gz"
- tar xzf swift-DEVELOPMENT-SNAPSHOT-2019-02-19-a-ubuntu16.04.tar.gz
- export PATH=$(pwd)/swift-DEVELOPMENT-SNAPSHOT-2019-02-19-a-ubuntu16.04/usr/bin:"${PATH}"
- swift --version
script:
- swift test
2 changes: 1 addition & 1 deletion BinaryCodable.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BinaryCodable'
s.version = '0.1.0'
s.version = '0.2.0'
s.license = 'Apache 2.0'
s.summary = 'Codable-like interfaces for binary representations.'
s.homepage = 'https://github.com/jverkoey/BinaryCodable'
Expand Down
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
# 0.2.0

This minor unstable release renames `sequentialContainer` to `container` for both the BinaryEncoder and BinaryDecoder types, adds support for `BinaryFloatingPoint` decoding and encoding, automatic BinaryCodable conformance for floating point and array types, and a variety of performance improvements.

## Breaking changes

`BinaryDecoder` and `BinaryEncoder`'s `sequentialContainer` has been renamed to `container`. This is a straightforward find-and-replace operation.

## New features

`Array<BinaryCodable>` types automatically conform to BinaryCodable. It's easier now to code sequential binary objects like so:

```swift
// Decoding
let objects = try container.decode([SomeBinaryObject].self)

// Encoding
try container.encode(objects)
```

`Float` and `Double` RawRepresentable types automatically conform to BinaryCodable.

## Source changes

* [Remove excessive conditionals and buffer containment. (#40)](https://github.com/jverkoey/BinaryCodable/commit/4daaee9f3cf4c66da0f488940f5681e03b510306) (featherless)
* [Remove unnecessary cast.](https://github.com/jverkoey/BinaryCodable/commit/5308cd3139368daac29f5f60b4fc22ae6cc59a57) (Jeff Verkoeyen)
* [Fix bug and improve performance. (#39)](https://github.com/jverkoey/BinaryCodable/commit/1e9c21bc4be6e5501825665c0a73f9e87b909ffa) (featherless)
* [Remove unnecessary Data creation. (#38)](https://github.com/jverkoey/BinaryCodable/commit/49ca3e2430a51af9fd37afb15ee9b902789153e3) (featherless)
* [Use dropFirst instead of subscript notation when reading data. (#37)](https://github.com/jverkoey/BinaryCodable/commit/b1889da65bde47336bf9fa9418cde40863ffb09e) (featherless)
* [Add floating point support. (#23)](https://github.com/jverkoey/BinaryCodable/commit/2e3185ec72a7371ef9402e46b80f161849052ae9) (featherless)
* [Add array coding support + tests. (#14)](https://github.com/jverkoey/BinaryCodable/commit/9a56a79308d1096c31479f1c592b5fa331be0707) (featherless)
* [Drop "Sequential" from the container name. (#12)](https://github.com/jverkoey/BinaryCodable/commit/6b9d1ab11d77f1654dc7ef9c28eec2f52dbccf8f) (featherless)

## Non-source changes

* [Update all docs with new container APIs. (#41)](https://github.com/jverkoey/BinaryCodable/commit/c2843b87559d485cbffe7b299fd31e6ac841dc59) (featherless)
* [Update README.md](https://github.com/jverkoey/BinaryCodable/commit/ec5d1f5256f07b004b210fd9b5f5e897030a34cb) (featherless)
* [Update README.md](https://github.com/jverkoey/BinaryCodable/commit/49ce0b41000a92306c326e80333af9a427611b48) (featherless)
* [Add BinaryCookies](https://github.com/jverkoey/BinaryCodable/commit/8f85cba939ed36003389dcc1b3fdfc941bf4a333) (featherless)
* [Add support for embedded types in the proto decoder. (#35)](https://github.com/jverkoey/BinaryCodable/commit/397ccc9bb1dff24bba000b7d42d82a0115a8c74c) (featherless)
* [Add bytes decoding support to the proto decoder. (#34)](https://github.com/jverkoey/BinaryCodable/commit/1328fce67b03b5a41d99730389f21068150d2d4a) (featherless)
* [Add String support to the proto decoder. (#33)](https://github.com/jverkoey/BinaryCodable/commit/07e1c1c3fea8ac4def6fa89639a7c30e9ace217d) (featherless)
* [Add bool support to the proto decoder. (#32)](https://github.com/jverkoey/BinaryCodable/commit/0e93d2224f1a5303ec411015f8ae312aa17beb28) (featherless)
* [Add sint64 support to the proto decoder. (#31)](https://github.com/jverkoey/BinaryCodable/commit/8108735cc28ec8ad1cda549b6b5ce30ca3783427) (featherless)
* [Add uint64 decoding support. (#30)](https://github.com/jverkoey/BinaryCodable/commit/8cbf0bf2f9f7048a1cae01c3f006be3f1a0d533a) (featherless)
* [Add support for optional proto decoding. (#29)](https://github.com/jverkoey/BinaryCodable/commit/b87134d57dc152978bc214f0c7c5a13a3c033144) (featherless)
* [Add double decoding support to the proto decoder. (#28)](https://github.com/jverkoey/BinaryCodable/commit/4c303bfa0d1a6e259ab55674a7afe18409e2ebad) (featherless)
* [Rename the message fields to match the underlying types. (#27)](https://github.com/jverkoey/BinaryCodable/commit/6d937eca935c2eaed901771be83d3c124aa338d8) (featherless)
* [Add proper fixed64 support to the proto decoder. (#26)](https://github.com/jverkoey/BinaryCodable/commit/1c227a1e8f15e709d42cf8cdf0a13221b7a96e49) (featherless)
* [ Add fixed32 support to the proto decoder. (#25)](https://github.com/jverkoey/BinaryCodable/commit/e135e3ca651b91cafe5bcb3ae5babec3935fbad3) (featherless)
* [Add double/fixed64 support to the proto proof of concept. (#24)](https://github.com/jverkoey/BinaryCodable/commit/6e32bee3c8fc98a0ab4b588a0fad0df6226e7769) (featherless)
* [Add a rudimentary Codable-compatible proto decoder built on top of a BinaryCodable message decoder. (#22)](https://github.com/jverkoey/BinaryCodable/commit/21cf2f7c4a7e03f039bd8750ee1e6c91869aecd2) (featherless)
* [Add sint32 proto tests (#21)](https://github.com/jverkoey/BinaryCodable/commit/33f58fc19bbc7ca2bdfd78cc1aee034cdf06607d) (featherless)
* [Add int64 proto tests. (#20)](https://github.com/jverkoey/BinaryCodable/commit/17adab86bedc1981254ac431134a1fd6ed812ab2) (featherless)
* [Add int32 overflow tests to verify the behavior of the protoc compiler. (#19)](https://github.com/jverkoey/BinaryCodable/commit/6d4b7c9eb11643904602c68bfb5079d5e71fe5d2) (featherless)
* [ Add proof of concept protobuf decoder tests (#15)](https://github.com/jverkoey/BinaryCodable/commit/96bf29b4f9fc808c5e1772fe2712f4018e1265ee) (featherless)
* [Update Swift to the latest development snapshot (#13)](https://github.com/jverkoey/BinaryCodable/commit/9cca6e629d352890181d81ce0d2dd47dd2bd6649) (featherless)
* [Update README.md](https://github.com/jverkoey/BinaryCodable/commit/176b7718796104ad22447b4ec86b9e09cb66d8af) (featherless)
* [Fix typo in readme. (#10)](https://github.com/jverkoey/BinaryCodable/commit/ba811ac24e7114628d22792e60620e144b410c88) (featherless)
* [Add missing linux tests. (#9)](https://github.com/jverkoey/BinaryCodable/commit/d2d2c558f0c4d205ff51816965dc3be62fb69a10) (featherless)

---

# 0.1.0

This is the first minor, unstable release of BinaryCodable. The public API for this library is subject to change unexpectedly until 1.0.0 is reached, at which point breaking changes will be mitigated and communicated ahead of time. This initial release includes the following features:
Expand Down
20 changes: 10 additions & 10 deletions Docs/ComparisonToSwiftCodable.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Swift Codable and Binary Codable's related types are outlined below.
| `Encodable` | `BinaryEncodable` |
| `Decodable` | `BinaryDecodable` |

| Swift Codable Encoder | Binary Codable Encoder |
|:-------------------------------|:------------------------------------|
| `KeyedEncodingContainer` | No equivalent |
| `UnkeyedEncodingContainer` | `SequentialBinaryEncodingContainer` |
| `SingleValueEncodingContainer` | No equivalent |
| Swift Codable Encoder | Binary Codable Encoder |
|:-------------------------------|:--------------------------|
| `KeyedEncodingContainer` | No equivalent |
| `UnkeyedEncodingContainer` | `BinaryEncodingContainer` |
| `SingleValueEncodingContainer` | No equivalent |

| Swift Codable Encoding Container | Binary Codable Encoding Container |
|:---------------------------------|:--------------------------------------------------------------------------|
Expand All @@ -34,11 +34,11 @@ Swift Codable and Binary Codable's related types are outlined below.
| `encode(_ value: String)` | `encode(_ value: String, encoding: String.Encoding, terminator: UInt8?)` |
| No equivalent | `encode<S>(sequence: S) throws where S: Sequence, S.Element == UInt8` |

| Swift Codable Decoder | Binary Codable Decoder |
|:-------------------------------|:------------------------------------|
| `KeyedDecodingContainer` | No equivalent |
| `UnkeyedDecodingContainer` | `SequentialBinaryDecodingContainer` |
| `SingleValueDecodingContainer` | No equivalent |
| Swift Codable Decoder | Binary Codable Decoder |
|:-------------------------------|:--------------------------|
| `KeyedDecodingContainer` | No equivalent |
| `UnkeyedDecodingContainer` | `BinaryDecodingContainer` |
| `SingleValueDecodingContainer` | No equivalent |

| Swift Codable Decoding Container | Binary Codable Decoding Container |
|:------------------------------------------------|:------------------------------------------------------------------------|
Expand Down
24 changes: 12 additions & 12 deletions Docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ struct GIFHeader {

We'll implement decoding first because it's easier to test our code against an existing gif file.

Aside: the biggest distinction between Swift Codable and Binary Codable is that we do not get encoding and decoding implementations for complex types for free. This is presently by design, though there are [opportunities for improving this in the future](https://github.com/jverkoey/BinaryCodable/issues/4). That being said, Binary Codable does provide automatic implementations for RawRepresentable types (namely enums with raw values).

```swift
// New
import BinaryCodable
Expand All @@ -41,6 +39,8 @@ let decoder = BinaryDataDecoder()
let header = try decoder.decode(GIFHeader.self, from: data)
```

Aside: the biggest distinction between Swift Codable and Binary Codable is that we do not get encoding and decoding implementations for complex types for free. This is presently by design, though there are [opportunities for improving this in the future](https://github.com/jverkoey/BinaryCodable/issues/4). That being said, Binary Codable does provide automatic implementations for RawRepresentable types (namely enums with raw values).

Like Swift Codable, we first create a sequential container.

Note: the container variable needs to be a `var` because we will mutate it.
Expand All @@ -52,7 +52,7 @@ struct GIFHeader: BinaryDecodable {
init(from decoder: BinaryDecoder) throws {
// New
// A nil maxLength means we don't know how long this container is.
var container = decoder.sequentialContainer(maxLength: nil)
var container = decoder.container(maxLength: nil)
}
}
```
Expand Down Expand Up @@ -82,7 +82,7 @@ import BinaryCodable
struct GIFHeader: BinaryDecodable {
init(from decoder: BinaryDecoder) throws {
// Modified
var container = decoder.sequentialContainer(maxLength: 13)
var container = decoder.container(maxLength: 13)
}
}
```
Expand Down Expand Up @@ -145,7 +145,7 @@ struct GIFHeader: BinaryDecodable {
By using an enum we've accomplished two things:

1. Clearly defined the expected values for this field.
2. Added error handling for unexpected values: if a GIF format version other than 87a or 89a are encountered, a `BinaryDecodingError.dataCorrupted` exception will be thrown.
2. Added error handling for unexpected values: if a GIF format version other than 87a or 89a is encountered, a `BinaryDecodingError.dataCorrupted` exception will be thrown.

Note: we can also apply this pattern to `signature` using a single-value String enum. Try cleaning up your implementation accordingly!

Expand Down Expand Up @@ -279,7 +279,7 @@ struct GIFHeader: BinaryDecodable {
let aspectRatio: UInt8

init(from decoder: BinaryDecoder) throws {
var container = decoder.sequentialContainer(maxLength: 13)
var container = decoder.container(maxLength: 13)

let signature = try container.decode(length: 3)
if signature != Data("GIF".utf8) {
Expand Down Expand Up @@ -351,7 +351,7 @@ import BinaryCodable
struct GIFHeader: BinaryCodable {
func encode(to encoder: BinaryEncoder) throws {
// New
var container = encoder.sequentialContainer()
var container = encoder.container()
}
}
```
Expand All @@ -363,7 +363,7 @@ import BinaryCodable

struct GIFHeader: BinaryCodable {
func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

// New
try container.encode("GIF", encoding: .ascii, terminator: nil)
Expand All @@ -383,7 +383,7 @@ struct GIFHeader: BinaryCodable {
case gif89a = "89a"
}
func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

try container.encode("GIF", encoding: .ascii, terminator: nil)
// New
Expand All @@ -399,7 +399,7 @@ import BinaryCodable

struct GIFHeader: BinaryCodable {
func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

try container.encode("GIF", encoding: .ascii, terminator: nil)
try container.encode(version)
Expand All @@ -420,7 +420,7 @@ struct GIFHeader: BinaryCodable {
struct Packed: OptionSet, BinaryCodable

func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

try container.encode("GIF", encoding: .ascii, terminator: nil)
try container.encode(version)
Expand Down Expand Up @@ -449,7 +449,7 @@ import BinaryCodable

struct GIFHeader: BinaryCodable {
func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

try container.encode("GIF", encoding: .ascii, terminator: nil)
try container.encode(version)
Expand Down
14 changes: 7 additions & 7 deletions Docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import BinaryCodable
struct <#DecodableObject#>: BinaryDecodable {

init(from decoder: BinaryDecoder) throws {
var container = decoder.sequentialContainer(maxLength: <#maxLengthOrNil#>)
var container = decoder.container(maxLength: <#maxLengthOrNil#>)

<#decoding logic#>
}
Expand All @@ -31,7 +31,7 @@ import BinaryCodable
struct <#EncodableObject#>: BinaryEncodable {

func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

<#encoding logic#>
}
Expand Down Expand Up @@ -82,7 +82,7 @@ import BinaryCodable
struct <#DecodableObject#>: BinaryDecodable {

init(from decoder: BinaryDecoder) throws {
var container = decoder.sequentialContainer(maxLength: <#maxLengthOrNil#>)
var container = decoder.container(maxLength: <#maxLengthOrNil#>)

let string = try container.decodeString(encoding: .utf8, terminator: 0)
}
Expand All @@ -97,7 +97,7 @@ import BinaryCodable
struct <#DecodableObject#>: BinaryDecodable {

init(from decoder: BinaryDecoder) throws {
var container = decoder.sequentialContainer(maxLength: <#maxLengthOrNil#>)
var container = decoder.container(maxLength: <#maxLengthOrNil#>)

var stringContainer = container.nestedContainer(maxLength: <#length#>)
let string = try stringContainer.decodeString(encoding: .utf8, terminator: nil)
Expand All @@ -113,7 +113,7 @@ import BinaryCodable
struct <#EncodableObject#>: BinaryEncodable {

func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

try container.encode("String", encoding: .utf8, terminator: 0)
}
Expand All @@ -128,7 +128,7 @@ import BinaryCodable
struct <#DecodableObject#>: BinaryDecodable {

init(from decoder: BinaryDecoder) throws {
var container = decoder.sequentialContainer(maxLength: nil)
var container = decoder.container(maxLength: nil)

let data = try container.decode(length: <#T##Int#>)
}
Expand All @@ -143,7 +143,7 @@ import BinaryCodable
struct <#EncodableObject#>: BinaryEncodable {

func encode(to encoder: BinaryEncoder) throws {
var container = encoder.sequentialContainer()
var container = encoder.container()

try container.encode(sequence: <#T##Sequence#>)
}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Binary Codable

Binary Codable provides Swift Codable-like interfaces for converting types into and from binary representations.
Binary Codable provides Swift Codable-like interfaces for converting types to and from binary representations.

Binary Codable is optimized for reading and writing blocks of binary data as a stream of bytes. This makes Binary Codable useful for network protocols, binary file formats, and other forms of tightly-packed binary information.

Expand Down Expand Up @@ -34,7 +34,8 @@ This is not an official Google product.

## Known usage in the wild

- [MySqlConnector](https://github.com/jverkoey/MySqlConnector): Translates between Swift types and MySql client/server protocol.
- [BinaryCookies](https://github.com/interstateone/BinaryCookies): Read and write Apple's .binarycookies files.
- [MySqlConnector](https://github.com/jverkoey/MySqlConnector): A pure Swift implementation of the MySql client/server protocol.

## Requirements

Expand Down
Loading

0 comments on commit 76b509f

Please sign in to comment.