Skip to content

Commit d7cb271

Browse files
committed
Merge branch 'release-candidate' into stable
2 parents 2f66977 + 7334036 commit d7cb271

19 files changed

+176
-1366
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: deploy_to_cocoapods
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
runs-on: macOS-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Install Cocoapods
14+
run: gem install cocoapods
15+
- uses: michaelhenry/[email protected]
16+
env:
17+
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}

.github/workflows/presubmit.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: presubmit
2+
on:
3+
pull_request:
4+
branches:
5+
- develop
6+
7+
jobs:
8+
mac_test:
9+
runs-on: macOS-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
- run: swift test
14+
15+
linux_test:
16+
container:
17+
image: swift:5.2
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- run: swift test --enable-test-discovery --enable-code-coverage
22+
- uses: mattpolzin/[email protected]
23+
24+
lint:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Run SwiftLint
29+
uses: norio-nomura/[email protected]
30+
with:
31+
args: --strict

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.2
1+
5.2

.travis.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

BinaryCodable.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Pod::Spec.new do |s|
22
s.name = 'BinaryCodable'
3-
s.version = '0.2.1'
3+
s.version = '0.3.0'
44
s.license = 'Apache 2.0'
55
s.summary = 'Codable-like interfaces for binary representations.'
66
s.homepage = 'https://github.com/jverkoey/BinaryCodable'
77
s.authors = { 'BinaryCodable authors' => '[email protected]' }
88
s.source = { :git => 'https://github.com/jverkoey/BinaryCodable.git', :tag => s.version }
99
s.documentation_url = 'https://github.com/jverkoey/BinaryCodable/'
1010

11-
s.ios.deployment_target = '12.0'
12-
s.osx.deployment_target = '10.12'
11+
s.ios.deployment_target = '13.0'
12+
s.osx.deployment_target = '10.15'
1313

1414
s.source_files = ['Sources/**/*.swift']
1515
end

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# 0.3.0
2+
3+
This minor release adds a `decodeRemainder` method to `BinaryDecodingContainer` and drops support for iOS 12, macOS 10.12-10.14, and Swift 4.
4+
5+
## Breaking changes
6+
7+
iOS 12, macOS 10.12-10.14, and Swift 4 are no longer supported.
8+
9+
## New features
10+
11+
* [Add decodeRemainder to BinaryDecodingContainer. (#47)](https://github.com/jverkoey/BinaryCodable/commit/2d4834e4972c46bdb3ec59d025ba29b7e9b7522b) (featherless)
12+
113
# 0.2.1
214

315
This patch releases updates the CocoaPods spec to include all BinaryCodable source. It was previously missing the coder implementations.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.2
22
// Copyright 2019-present the BinaryCodable authors. All Rights Reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,6 +31,6 @@ let package = Package(
3131
.testTarget(
3232
name: "BinaryCodableTests",
3333
dependencies: ["BinaryCodable"]
34-
),
34+
)
3535
]
3636
)

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ This is not an official Google product.
3737
- [BinaryCookies](https://github.com/interstateone/BinaryCookies): Read and write Apple's .binarycookies files.
3838
- [MySqlConnector](https://github.com/jverkoey/MySqlConnector): A pure Swift implementation of the MySql client/server protocol.
3939

40-
## Requirements
41-
42-
- Swift 4.2.2+
43-
4440
## Supported technologies
4541

46-
- iOS 12.0+ / macOS 10.12+
47-
- Xcode 10.1+
42+
- iOS 13.0+ / macOS 10.15+
43+
- Xcode 11.5+
4844
- Ubuntu 16.04
45+
- Swift 5.2
4946

5047
## License
5148

Sources/BinaryCodable/BinaryDataCoders/BinaryDataDecoder.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ private class BinaryDataDecodingContainer: BinaryDecodingContainer {
111111
throw BinaryDecodingError.dataCorrupted(.init(debugDescription:
112112
"Not enough data to create a a type of \(type). Needed: \(byteWidth). Received: \(bytes.count)."))
113113
}
114-
let value = bytes.withUnsafeBytes { (ptr: UnsafePointer<T>) -> T in
115-
return ptr.pointee
114+
let value = bytes.withUnsafeBytes { ptr -> T in
115+
return ptr.load(as: T.self)
116116
}
117117
return value
118118
}
@@ -124,8 +124,8 @@ private class BinaryDataDecodingContainer: BinaryDecodingContainer {
124124
throw BinaryDecodingError.dataCorrupted(.init(debugDescription:
125125
"Not enough data to create a a type of \(type). Needed: \(byteWidth). Received: \(bytes.count)."))
126126
}
127-
let value = bytes.withUnsafeBytes { (ptr: UnsafePointer<T>) -> T in
128-
return ptr.pointee
127+
let value = bytes.withUnsafeBytes { ptr -> T in
128+
return ptr.load(as: T.self)
129129
}
130130
return value
131131
}
@@ -165,6 +165,10 @@ private class BinaryDataDecodingContainer: BinaryDecodingContainer {
165165
return data
166166
}
167167

168+
func decodeRemainder() throws -> Data {
169+
return try pullData(length: Int.max)
170+
}
171+
168172
func nestedContainer(maxLength: Int?) -> BinaryDecodingContainer {
169173
let length: Int?
170174
let bufferedData: BufferedData

Sources/BinaryCodable/BinaryDataCoders/ByteRepresentations.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extension BinaryFloatingPoint {
2929
Returns a byte array representation of a floating point number.
3030
*/
3131
public var bytes: [UInt8] {
32-
var value = self
33-
let data = Data(buffer: UnsafeBufferPointer(start: &value, count: 1))
34-
return [UInt8](data)
32+
return [UInt8](withUnsafeBytes(of: self) { Data($0) })
3533
}
3634
}

Sources/BinaryCodable/BinaryDecodable.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ public protocol BinaryDecodingContainer {
135135
*/
136136
mutating func decode(length: Int) throws -> Data
137137

138+
/**
139+
Decodes the remainder of available data.
140+
141+
- returns: A Data representation of the decoded bytes.
142+
*/
143+
mutating func decodeRemainder() throws -> Data
144+
138145
/**
139146
Reads `length` bytes without affecting the `decode` cursor.
140147

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2019-present the BinaryCodable authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import BinaryCodable
16+
import XCTest
17+
18+
private struct Packet: BinaryDecodable {
19+
let data: Data
20+
let decoderWasAtEnd: Bool
21+
init(from decoder: BinaryDecoder) throws {
22+
var container = decoder.container(maxLength: nil)
23+
self.data = try container.decodeRemainder()
24+
self.decoderWasAtEnd = container.isAtEnd
25+
}
26+
}
27+
28+
private struct NestedPacket: BinaryDecodable {
29+
let data: Data
30+
let decoderWasAtEnd: Bool
31+
let nestedDecoderWasAtEnd: Bool
32+
init(from decoder: BinaryDecoder) throws {
33+
var container = decoder.container(maxLength: nil)
34+
var nestedContainer = container.nestedContainer(maxLength: 2)
35+
self.data = try nestedContainer.decodeRemainder()
36+
self.decoderWasAtEnd = container.isAtEnd
37+
self.nestedDecoderWasAtEnd = nestedContainer.isAtEnd
38+
}
39+
}
40+
41+
final class DecodeRemainderTests: XCTestCase {
42+
43+
func testDecodesAllBytes() throws {
44+
// Given
45+
let packetData: [UInt8] = [0, 0, 0, 0]
46+
let decoder = BinaryDataDecoder()
47+
48+
// When
49+
let packet = try decoder.decode(Packet.self, from: packetData)
50+
51+
// Then
52+
XCTAssertEqual([UInt8](packet.data), [0, 0, 0, 0])
53+
XCTAssertTrue(packet.decoderWasAtEnd)
54+
}
55+
56+
func testDecodesAllContainerBytes() throws {
57+
// Given
58+
let packetData: [UInt8] = [0, 0, 0, 0]
59+
let decoder = BinaryDataDecoder()
60+
61+
// When
62+
let packet = try decoder.decode(NestedPacket.self, from: packetData)
63+
64+
// Then
65+
XCTAssertEqual([UInt8](packet.data), [0, 0])
66+
XCTAssertFalse(packet.decoderWasAtEnd)
67+
XCTAssertTrue(packet.nestedDecoderWasAtEnd)
68+
}
69+
}

Tests/BinaryCodableTests/GIFHeaderTests.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ struct GIFHeader: BinaryCodable {
5454
let backgroundColorIndex: UInt8
5555
let aspectRatio: UInt8
5656

57-
init(version: Version, width: UInt16, height: UInt16, numberOfGlobalColorTableEntries: Int, colorTableEntriesSortedByImportance: Bool, colorResolution: UInt8, hasGlobalColorTable: Bool, backgroundColorIndex: UInt8, aspectRatio: UInt8) {
57+
init(
58+
version: Version,
59+
width: UInt16,
60+
height: UInt16,
61+
numberOfGlobalColorTableEntries: Int,
62+
colorTableEntriesSortedByImportance: Bool,
63+
colorResolution: UInt8,
64+
hasGlobalColorTable: Bool,
65+
backgroundColorIndex: UInt8,
66+
aspectRatio: UInt8
67+
) {
5868
self.version = version
5969
self.screenWidth = width
6070
self.screenHeight = height
@@ -145,7 +155,17 @@ final class GIFDecoderTests: XCTestCase {
145155

146156
func testEncoding() throws {
147157
// Given
148-
let header = GIFHeader(version: .gif89a, width: 46, height: 37, numberOfGlobalColorTableEntries: 4, colorTableEntriesSortedByImportance: false, colorResolution: 8, hasGlobalColorTable: true, backgroundColorIndex: 0, aspectRatio: 0)
158+
let header = GIFHeader(
159+
version: .gif89a,
160+
width: 46,
161+
height: 37,
162+
numberOfGlobalColorTableEntries: 4,
163+
colorTableEntriesSortedByImportance: false,
164+
colorResolution: 8,
165+
hasGlobalColorTable: true,
166+
backgroundColorIndex: 0,
167+
aspectRatio: 0
168+
)
149169
let encoder = BinaryDataEncoder()
150170

151171
// When

0 commit comments

Comments
 (0)