Skip to content

Commit 76b509f

Browse files
committed
Merge branch 'release-candidate' into stable
2 parents 3a38a02 + c96cb07 commit 76b509f

27 files changed

+1685
-116
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.build
33
/Packages
44
/*.xcodeproj
5+
bin/protoc

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ matrix:
1212
os: osx
1313
osx_image: xcode10.1
1414
language: swift
15+
before_script:
16+
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-osx-x86_64.zip
17+
- unzip protoc-3.6.1-osx-x86_64.zip
1518
script:
1619
- swift test
1720

@@ -20,6 +23,8 @@ matrix:
2023
dist: xenial
2124
language: c
2225
before_script:
26+
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip
27+
- unzip protoc-3.6.1-linux-x86_64.zip
2328
- 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
2429
- tar xzf swift-4.2.2-RELEASE-ubuntu16.04.tar.gz
2530
- export PATH=$(pwd)/swift-4.2.2-RELEASE-ubuntu16.04/usr/bin:"${PATH}"
@@ -32,9 +37,11 @@ matrix:
3237
dist: xenial
3338
language: c
3439
before_script:
35-
- 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"
36-
- tar xzf swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-ubuntu16.04.tar.gz
37-
- export PATH=$(pwd)/swift-DEVELOPMENT-SNAPSHOT-2019-02-14-a-ubuntu16.04/usr/bin:"${PATH}"
40+
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip
41+
- unzip protoc-3.6.1-linux-x86_64.zip
42+
- 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"
43+
- tar xzf swift-DEVELOPMENT-SNAPSHOT-2019-02-19-a-ubuntu16.04.tar.gz
44+
- export PATH=$(pwd)/swift-DEVELOPMENT-SNAPSHOT-2019-02-19-a-ubuntu16.04/usr/bin:"${PATH}"
3845
- swift --version
3946
script:
4047
- swift test

BinaryCodable.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'BinaryCodable'
3-
s.version = '0.1.0'
3+
s.version = '0.2.0'
44
s.license = 'Apache 2.0'
55
s.summary = 'Codable-like interfaces for binary representations.'
66
s.homepage = 'https://github.com/jverkoey/BinaryCodable'

CHANGELOG.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,66 @@
1+
# 0.2.0
2+
3+
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.
4+
5+
## Breaking changes
6+
7+
`BinaryDecoder` and `BinaryEncoder`'s `sequentialContainer` has been renamed to `container`. This is a straightforward find-and-replace operation.
8+
9+
## New features
10+
11+
`Array<BinaryCodable>` types automatically conform to BinaryCodable. It's easier now to code sequential binary objects like so:
12+
13+
```swift
14+
// Decoding
15+
let objects = try container.decode([SomeBinaryObject].self)
16+
17+
// Encoding
18+
try container.encode(objects)
19+
```
20+
21+
`Float` and `Double` RawRepresentable types automatically conform to BinaryCodable.
22+
23+
## Source changes
24+
25+
* [Remove excessive conditionals and buffer containment. (#40)](https://github.com/jverkoey/BinaryCodable/commit/4daaee9f3cf4c66da0f488940f5681e03b510306) (featherless)
26+
* [Remove unnecessary cast.](https://github.com/jverkoey/BinaryCodable/commit/5308cd3139368daac29f5f60b4fc22ae6cc59a57) (Jeff Verkoeyen)
27+
* [Fix bug and improve performance. (#39)](https://github.com/jverkoey/BinaryCodable/commit/1e9c21bc4be6e5501825665c0a73f9e87b909ffa) (featherless)
28+
* [Remove unnecessary Data creation. (#38)](https://github.com/jverkoey/BinaryCodable/commit/49ca3e2430a51af9fd37afb15ee9b902789153e3) (featherless)
29+
* [Use dropFirst instead of subscript notation when reading data. (#37)](https://github.com/jverkoey/BinaryCodable/commit/b1889da65bde47336bf9fa9418cde40863ffb09e) (featherless)
30+
* [Add floating point support. (#23)](https://github.com/jverkoey/BinaryCodable/commit/2e3185ec72a7371ef9402e46b80f161849052ae9) (featherless)
31+
* [Add array coding support + tests. (#14)](https://github.com/jverkoey/BinaryCodable/commit/9a56a79308d1096c31479f1c592b5fa331be0707) (featherless)
32+
* [Drop "Sequential" from the container name. (#12)](https://github.com/jverkoey/BinaryCodable/commit/6b9d1ab11d77f1654dc7ef9c28eec2f52dbccf8f) (featherless)
33+
34+
## Non-source changes
35+
36+
* [Update all docs with new container APIs. (#41)](https://github.com/jverkoey/BinaryCodable/commit/c2843b87559d485cbffe7b299fd31e6ac841dc59) (featherless)
37+
* [Update README.md](https://github.com/jverkoey/BinaryCodable/commit/ec5d1f5256f07b004b210fd9b5f5e897030a34cb) (featherless)
38+
* [Update README.md](https://github.com/jverkoey/BinaryCodable/commit/49ce0b41000a92306c326e80333af9a427611b48) (featherless)
39+
* [Add BinaryCookies](https://github.com/jverkoey/BinaryCodable/commit/8f85cba939ed36003389dcc1b3fdfc941bf4a333) (featherless)
40+
* [Add support for embedded types in the proto decoder. (#35)](https://github.com/jverkoey/BinaryCodable/commit/397ccc9bb1dff24bba000b7d42d82a0115a8c74c) (featherless)
41+
* [Add bytes decoding support to the proto decoder. (#34)](https://github.com/jverkoey/BinaryCodable/commit/1328fce67b03b5a41d99730389f21068150d2d4a) (featherless)
42+
* [Add String support to the proto decoder. (#33)](https://github.com/jverkoey/BinaryCodable/commit/07e1c1c3fea8ac4def6fa89639a7c30e9ace217d) (featherless)
43+
* [Add bool support to the proto decoder. (#32)](https://github.com/jverkoey/BinaryCodable/commit/0e93d2224f1a5303ec411015f8ae312aa17beb28) (featherless)
44+
* [Add sint64 support to the proto decoder. (#31)](https://github.com/jverkoey/BinaryCodable/commit/8108735cc28ec8ad1cda549b6b5ce30ca3783427) (featherless)
45+
* [Add uint64 decoding support. (#30)](https://github.com/jverkoey/BinaryCodable/commit/8cbf0bf2f9f7048a1cae01c3f006be3f1a0d533a) (featherless)
46+
* [Add support for optional proto decoding. (#29)](https://github.com/jverkoey/BinaryCodable/commit/b87134d57dc152978bc214f0c7c5a13a3c033144) (featherless)
47+
* [Add double decoding support to the proto decoder. (#28)](https://github.com/jverkoey/BinaryCodable/commit/4c303bfa0d1a6e259ab55674a7afe18409e2ebad) (featherless)
48+
* [Rename the message fields to match the underlying types. (#27)](https://github.com/jverkoey/BinaryCodable/commit/6d937eca935c2eaed901771be83d3c124aa338d8) (featherless)
49+
* [Add proper fixed64 support to the proto decoder. (#26)](https://github.com/jverkoey/BinaryCodable/commit/1c227a1e8f15e709d42cf8cdf0a13221b7a96e49) (featherless)
50+
* [ Add fixed32 support to the proto decoder. (#25)](https://github.com/jverkoey/BinaryCodable/commit/e135e3ca651b91cafe5bcb3ae5babec3935fbad3) (featherless)
51+
* [Add double/fixed64 support to the proto proof of concept. (#24)](https://github.com/jverkoey/BinaryCodable/commit/6e32bee3c8fc98a0ab4b588a0fad0df6226e7769) (featherless)
52+
* [Add a rudimentary Codable-compatible proto decoder built on top of a BinaryCodable message decoder. (#22)](https://github.com/jverkoey/BinaryCodable/commit/21cf2f7c4a7e03f039bd8750ee1e6c91869aecd2) (featherless)
53+
* [Add sint32 proto tests (#21)](https://github.com/jverkoey/BinaryCodable/commit/33f58fc19bbc7ca2bdfd78cc1aee034cdf06607d) (featherless)
54+
* [Add int64 proto tests. (#20)](https://github.com/jverkoey/BinaryCodable/commit/17adab86bedc1981254ac431134a1fd6ed812ab2) (featherless)
55+
* [Add int32 overflow tests to verify the behavior of the protoc compiler. (#19)](https://github.com/jverkoey/BinaryCodable/commit/6d4b7c9eb11643904602c68bfb5079d5e71fe5d2) (featherless)
56+
* [ Add proof of concept protobuf decoder tests (#15)](https://github.com/jverkoey/BinaryCodable/commit/96bf29b4f9fc808c5e1772fe2712f4018e1265ee) (featherless)
57+
* [Update Swift to the latest development snapshot (#13)](https://github.com/jverkoey/BinaryCodable/commit/9cca6e629d352890181d81ce0d2dd47dd2bd6649) (featherless)
58+
* [Update README.md](https://github.com/jverkoey/BinaryCodable/commit/176b7718796104ad22447b4ec86b9e09cb66d8af) (featherless)
59+
* [Fix typo in readme. (#10)](https://github.com/jverkoey/BinaryCodable/commit/ba811ac24e7114628d22792e60620e144b410c88) (featherless)
60+
* [Add missing linux tests. (#9)](https://github.com/jverkoey/BinaryCodable/commit/d2d2c558f0c4d205ff51816965dc3be62fb69a10) (featherless)
61+
62+
---
63+
164
# 0.1.0
265

366
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:

Docs/ComparisonToSwiftCodable.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Swift Codable and Binary Codable's related types are outlined below.
1414
| `Encodable` | `BinaryEncodable` |
1515
| `Decodable` | `BinaryDecodable` |
1616

17-
| Swift Codable Encoder | Binary Codable Encoder |
18-
|:-------------------------------|:------------------------------------|
19-
| `KeyedEncodingContainer` | No equivalent |
20-
| `UnkeyedEncodingContainer` | `SequentialBinaryEncodingContainer` |
21-
| `SingleValueEncodingContainer` | No equivalent |
17+
| Swift Codable Encoder | Binary Codable Encoder |
18+
|:-------------------------------|:--------------------------|
19+
| `KeyedEncodingContainer` | No equivalent |
20+
| `UnkeyedEncodingContainer` | `BinaryEncodingContainer` |
21+
| `SingleValueEncodingContainer` | No equivalent |
2222

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

37-
| Swift Codable Decoder | Binary Codable Decoder |
38-
|:-------------------------------|:------------------------------------|
39-
| `KeyedDecodingContainer` | No equivalent |
40-
| `UnkeyedDecodingContainer` | `SequentialBinaryDecodingContainer` |
41-
| `SingleValueDecodingContainer` | No equivalent |
37+
| Swift Codable Decoder | Binary Codable Decoder |
38+
|:-------------------------------|:--------------------------|
39+
| `KeyedDecodingContainer` | No equivalent |
40+
| `UnkeyedDecodingContainer` | `BinaryDecodingContainer` |
41+
| `SingleValueDecodingContainer` | No equivalent |
4242

4343
| Swift Codable Decoding Container | Binary Codable Decoding Container |
4444
|:------------------------------------------------|:------------------------------------------------------------------------|

Docs/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ struct GIFHeader {
2222

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

25-
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).
26-
2725
```swift
2826
// New
2927
import BinaryCodable
@@ -41,6 +39,8 @@ let decoder = BinaryDataDecoder()
4139
let header = try decoder.decode(GIFHeader.self, from: data)
4240
```
4341

42+
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).
43+
4444
Like Swift Codable, we first create a sequential container.
4545

4646
Note: the container variable needs to be a `var` because we will mutate it.
@@ -52,7 +52,7 @@ struct GIFHeader: BinaryDecodable {
5252
init(from decoder: BinaryDecoder) throws {
5353
// New
5454
// A nil maxLength means we don't know how long this container is.
55-
var container = decoder.sequentialContainer(maxLength: nil)
55+
var container = decoder.container(maxLength: nil)
5656
}
5757
}
5858
```
@@ -82,7 +82,7 @@ import BinaryCodable
8282
struct GIFHeader: BinaryDecodable {
8383
init(from decoder: BinaryDecoder) throws {
8484
// Modified
85-
var container = decoder.sequentialContainer(maxLength: 13)
85+
var container = decoder.container(maxLength: 13)
8686
}
8787
}
8888
```
@@ -145,7 +145,7 @@ struct GIFHeader: BinaryDecodable {
145145
By using an enum we've accomplished two things:
146146

147147
1. Clearly defined the expected values for this field.
148-
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.
148+
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.
149149

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

@@ -279,7 +279,7 @@ struct GIFHeader: BinaryDecodable {
279279
let aspectRatio: UInt8
280280

281281
init(from decoder: BinaryDecoder) throws {
282-
var container = decoder.sequentialContainer(maxLength: 13)
282+
var container = decoder.container(maxLength: 13)
283283

284284
let signature = try container.decode(length: 3)
285285
if signature != Data("GIF".utf8) {
@@ -351,7 +351,7 @@ import BinaryCodable
351351
struct GIFHeader: BinaryCodable {
352352
func encode(to encoder: BinaryEncoder) throws {
353353
// New
354-
var container = encoder.sequentialContainer()
354+
var container = encoder.container()
355355
}
356356
}
357357
```
@@ -363,7 +363,7 @@ import BinaryCodable
363363

364364
struct GIFHeader: BinaryCodable {
365365
func encode(to encoder: BinaryEncoder) throws {
366-
var container = encoder.sequentialContainer()
366+
var container = encoder.container()
367367

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

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

400400
struct GIFHeader: BinaryCodable {
401401
func encode(to encoder: BinaryEncoder) throws {
402-
var container = encoder.sequentialContainer()
402+
var container = encoder.container()
403403

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

422422
func encode(to encoder: BinaryEncoder) throws {
423-
var container = encoder.sequentialContainer()
423+
var container = encoder.container()
424424

425425
try container.encode("GIF", encoding: .ascii, terminator: nil)
426426
try container.encode(version)
@@ -449,7 +449,7 @@ import BinaryCodable
449449

450450
struct GIFHeader: BinaryCodable {
451451
func encode(to encoder: BinaryEncoder) throws {
452-
var container = encoder.sequentialContainer()
452+
var container = encoder.container()
453453

454454
try container.encode("GIF", encoding: .ascii, terminator: nil)
455455
try container.encode(version)

Docs/Usage.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import BinaryCodable
1010
struct <#DecodableObject#>: BinaryDecodable {
1111

1212
init(from decoder: BinaryDecoder) throws {
13-
var container = decoder.sequentialContainer(maxLength: <#maxLengthOrNil#>)
13+
var container = decoder.container(maxLength: <#maxLengthOrNil#>)
1414

1515
<#decoding logic#>
1616
}
@@ -31,7 +31,7 @@ import BinaryCodable
3131
struct <#EncodableObject#>: BinaryEncodable {
3232

3333
func encode(to encoder: BinaryEncoder) throws {
34-
var container = encoder.sequentialContainer()
34+
var container = encoder.container()
3535

3636
<#encoding logic#>
3737
}
@@ -82,7 +82,7 @@ import BinaryCodable
8282
struct <#DecodableObject#>: BinaryDecodable {
8383

8484
init(from decoder: BinaryDecoder) throws {
85-
var container = decoder.sequentialContainer(maxLength: <#maxLengthOrNil#>)
85+
var container = decoder.container(maxLength: <#maxLengthOrNil#>)
8686

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

9999
init(from decoder: BinaryDecoder) throws {
100-
var container = decoder.sequentialContainer(maxLength: <#maxLengthOrNil#>)
100+
var container = decoder.container(maxLength: <#maxLengthOrNil#>)
101101

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

115115
func encode(to encoder: BinaryEncoder) throws {
116-
var container = encoder.sequentialContainer()
116+
var container = encoder.container()
117117

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

130130
init(from decoder: BinaryDecoder) throws {
131-
var container = decoder.sequentialContainer(maxLength: nil)
131+
var container = decoder.container(maxLength: nil)
132132

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

145145
func encode(to encoder: BinaryEncoder) throws {
146-
var container = encoder.sequentialContainer()
146+
var container = encoder.container()
147147

148148
try container.encode(sequence: <#T##Sequence#>)
149149
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Binary Codable
22

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

55
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.
66

@@ -34,7 +34,8 @@ This is not an official Google product.
3434

3535
## Known usage in the wild
3636

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

3940
## Requirements
4041

0 commit comments

Comments
 (0)