Skip to content

Commit a16e37d

Browse files
committed
Merge branch 'release-1.1.0'
2 parents 279ac65 + 88b8690 commit a16e37d

15 files changed

Lines changed: 180 additions & 47 deletions

.jazzy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ sourcekitten_sourcefile: docs.json
33
clean: true
44
author: Timofey Solomko
55
module: BitByteData
6-
module_version: 1.0.2
6+
module_version: 1.1.0
77
copyright: '© 2018 Timofey Solomko'
88
readme: README.md
99
github_url: https://github.com/tsolomko/BitByteData
10-
github_file_prefix: https://github.com/tsolomko/BitByteData/tree/1.0.2
10+
github_file_prefix: https://github.com/tsolomko/BitByteData/tree/1.1.0
1111
theme: fullwidth
1212

1313
custom_categories:

.swiftlint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
excluded:
2+
- .build/
13
opt_in_rules:
24
- array_init
35
- block_based_kvo
46
- conditional_returns_on_newline
57
- contains_over_first_not_nil
68
- discouraged_direct_init
79
- discouraged_object_literal
10+
- discouraged_optional_boolean
811
- explicit_init
912
- fatal_error_message
1013
- first_where

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ jobs:
22
include:
33
- stage: test
44
language: objective-c
5+
os: osx
56
osx_image: xcode9.2
67
script:
78
- swift build
@@ -19,6 +20,7 @@ jobs:
1920
- stage: deploy
2021
if: tag IS present
2122
language: objective-c
23+
os: osx
2224
osx_image: xcode9.2
2325
env:
2426
secure: fmKQgrPRx2iisNPzxDhOTfXPsnQMJxDgIMItVNjl1AKByraOpiDAGVESySvy+vwQqITCB/BfvdkW7smAPcvFJxIPRx1v4J0VY9kGHdnafMw35XY0Vj9soYkzNS4zrUebxY2gWkGM6Q6dgLOGT/9MSEyWqXBTtVz9sLwA7yr3ZI72yZDbcSz3XGa1fFZRVfwv3I+bmuozG7dq7tyqcSKgRZnHg1VvaRdxcaGqSGSUsNu0YLzmNedujNcU+gTXcxMdrXA1eaheHc2pwNA0TDf3KkefJpaVMXrA/Un8e9MaJ1lMnPlIiEI3dPTuogtQY7p59vgulBNBPEJovTHI0jCaNyLUkTkHgGcUuOwHqwUIKZCEiiqM1j12sdLo4O2tAdNaNHDtd8D3bCakrdJxXlUWVfjrCwvBB555gd0drRirQgYX+5gGFwnTQE8tOcjK4qUvJaOAouHsnm/DmW+fLJPX76KoU6QOtGJt6PQ92yBgKRhaSg/sQ28WPuCmF2p7BuUSuULxcM2LU5eA5aFxayoZvR2E9uvfFxnFh01iV6clcZo25U03AuxJmuI7Mhl83amj8bm5CRBbuRw5sIljXfBujFUel+kz/HXalS7lStqH9iPyiQvh24WkPzHKNQdjRI7v3kyrVSXJ3Xl6+fopXqr/25MwqD4bt57QgglJ2IQtnLM=

BitByteData.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "BitByteData"
4-
s.version = "1.0.2"
4+
s.version = "1.1.0"
55
s.summary = "Read and write bits and bytes in Swift."
66

77
s.description = "A Swift framework with classes for reading and writing bits and bytes."

BitByteData.xcodeproj/BitByteData.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.2</string>
18+
<string>1.1.0</string>
1919
<key>CFBundleVersion</key>
20-
<string>6</string>
20+
<string>8</string>
2121
<key>NSHumanReadableCopyright</key>
2222
<string>Copyright © 2018 Timofey Solomko. All rights reserved.</string>
2323
</dict>

BitByteData.xcodeproj/TestBitByteData.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.2</string>
18+
<string>1.1.0</string>
1919
<key>CFBundleVersion</key>
20-
<string>6</string>
20+
<string>8</string>
2121
</dict>
2222
</plist>

BitByteData.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
CLANG_WARN_SUSPICIOUS_MOVE = YES;
249249
CLANG_WARN_UNREACHABLE_CODE = YES;
250250
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
251-
CURRENT_PROJECT_VERSION = 6;
251+
CURRENT_PROJECT_VERSION = 8;
252252
DEBUG_INFORMATION_FORMAT = dwarf;
253253
ENABLE_STRICT_OBJC_MSGSEND = YES;
254254
ENABLE_TESTABILITY = YES;
@@ -290,7 +290,7 @@
290290
CLANG_WARN_SUSPICIOUS_MOVE = YES;
291291
CLANG_WARN_UNREACHABLE_CODE = YES;
292292
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
293-
CURRENT_PROJECT_VERSION = 6;
293+
CURRENT_PROJECT_VERSION = 8;
294294
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
295295
ENABLE_STRICT_OBJC_MSGSEND = YES;
296296
GCC_NO_COMMON_BLOCKS = YES;
@@ -318,7 +318,7 @@
318318
APPLICATION_EXTENSION_API_ONLY = YES;
319319
DEFINES_MODULE = YES;
320320
DYLIB_COMPATIBILITY_VERSION = 1;
321-
DYLIB_CURRENT_VERSION = 6;
321+
DYLIB_CURRENT_VERSION = 8;
322322
DYLIB_INSTALL_NAME_BASE = "@rpath";
323323
INFOPLIST_FILE = BitByteData.xcodeproj/BitByteData.plist;
324324
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -337,7 +337,7 @@
337337
APPLICATION_EXTENSION_API_ONLY = YES;
338338
DEFINES_MODULE = YES;
339339
DYLIB_COMPATIBILITY_VERSION = 1;
340-
DYLIB_CURRENT_VERSION = 6;
340+
DYLIB_CURRENT_VERSION = 8;
341341
DYLIB_INSTALL_NAME_BASE = "@rpath";
342342
INFOPLIST_FILE = BitByteData.xcodeproj/BitByteData.plist;
343343
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.1.0
4+
5+
- Added converting from `ByteReader` initializers to `LsbBitReader` and `MsbBitReader`, as well as `BitReader` protocol.
6+
- Added `bitsLeft` and `bitsRead` computed properties to `LsbBitReader` and `MsbBitReader`, as well as `BitReader`
7+
protocol.
8+
39
## 1.0.2
410

511
- Fix several problems causing incorrect preconditions failures.

Sources/BitReader.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ public protocol BitReader: class {
1111
/// True, if reader's BIT pointer is aligned with the BYTE border.
1212
var isAligned: Bool { get }
1313

14+
// Amount of bits left to read.
15+
var bitsLeft: Int { get }
16+
17+
// Amount of bits that were already read.
18+
var bitsRead: Int { get }
19+
1420
/// Creates an instance for reading bits (and bytes) from `data`.
1521
init(data: Data)
1622

23+
/**
24+
Converts a `ByteReader` instance into `BitReader`, enabling bits reading capabilities. Current `offset` value of
25+
`byteReader` is preserved.
26+
*/
27+
init(_ byteReader: ByteReader)
28+
1729
/// Reads bit and returns it, advancing by one BIT position.
1830
func bit() -> UInt8
1931

Sources/ByteReader.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public class ByteReader {
4141
*/
4242
public func byte() -> UInt8 {
4343
precondition(self.offset < self.data.endIndex)
44-
self.offset += 1
45-
return self.data[self.offset - 1]
44+
defer { self.offset += 1 }
45+
return self.data[self.offset]
4646
}
4747

4848
/**
@@ -56,9 +56,8 @@ public class ByteReader {
5656
guard count > 0
5757
else { return [] }
5858
precondition(self.offset + count <= self.data.endIndex)
59-
let result = self.data[self.offset..<self.offset + count].toArray(type: UInt8.self, count: count)
60-
self.offset += count
61-
return result
59+
defer { self.offset += count }
60+
return self.data[self.offset..<self.offset + count].toArray(type: UInt8.self, count: count)
6261
}
6362

6463
/**
@@ -68,9 +67,8 @@ public class ByteReader {
6867
*/
6968
public func uint64() -> UInt64 {
7069
precondition(self.offset + 8 <= self.data.endIndex)
71-
let result = self.data[self.offset..<self.offset + 8].to(type: UInt64.self)
72-
self.offset += 8
73-
return result
70+
defer { self.offset += 8 }
71+
return self.data[self.offset..<self.offset + 8].to(type: UInt64.self)
7472
}
7573

7674
/**
@@ -80,9 +78,8 @@ public class ByteReader {
8078
*/
8179
public func uint32() -> UInt32 {
8280
precondition(self.offset + 4 <= self.data.endIndex)
83-
let result = self.data[self.offset..<self.offset + 4].to(type: UInt32.self)
84-
self.offset += 4
85-
return result
81+
defer { self.offset += 4 }
82+
return self.data[self.offset..<self.offset + 4].to(type: UInt32.self)
8683
}
8784

8885
/**
@@ -92,9 +89,8 @@ public class ByteReader {
9289
*/
9390
public func uint16() -> UInt16 {
9491
precondition(self.offset + 2 <= self.data.endIndex)
95-
let result = self.data[self.offset..<self.offset + 2].to(type: UInt16.self)
96-
self.offset += 2
97-
return result
92+
defer { self.offset += 2 }
93+
return self.data[self.offset..<self.offset + 2].to(type: UInt16.self)
9894
}
9995

10096
}

0 commit comments

Comments
 (0)