Skip to content

Commit 4833577

Browse files
committed
Merge branch 'release-1.1.0' into develop
2 parents 3c05981 + 88b8690 commit 4833577

14 files changed

Lines changed: 144 additions & 48 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:

.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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ 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

17-
// TODO: Add `init(_ byteReader: ByteReader)`?
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)
1828

1929
/// Reads bit and returns it, advancing by one BIT position.
2030
func bit() -> UInt8

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
}

Sources/LsbBitReader.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,46 @@ public final class LsbBitReader: ByteReader, BitReader {
1111
private var bitMask: UInt8 = 1
1212
private var currentByte: UInt8
1313

14-
private var bitsLeft: Int {
15-
if isFinished {
14+
/// True, if reader's BIT pointer is aligned with the BYTE border.
15+
public var isAligned: Bool {
16+
return self.bitMask == 1
17+
}
18+
19+
// Amount of bits left to read.
20+
public var bitsLeft: Int {
21+
if self.isFinished {
1622
return 0
1723
} else {
18-
return (self.data.endIndex - self.offset) * 8 + 8 - bitMask.trailingZeroBitCount
24+
return (self.data.endIndex - self.offset) * 8 - self.bitMask.trailingZeroBitCount
1925
}
2026
}
2127

28+
// Amount of bits that were already read.
29+
public var bitsRead: Int {
30+
if self.isFinished {
31+
return 8 * self.size
32+
} else {
33+
return (self.offset - self.data.startIndex) * 8 + self.bitMask.trailingZeroBitCount
34+
}
35+
36+
}
37+
2238
/// Creates an instance for reading bits (and bytes) from `data`.
2339
public override init(data: Data) {
2440
self.currentByte = data.first ?? 0
2541
super.init(data: data)
2642
}
2743

2844
/**
29-
Converts a `ByteReader` instance into `LsbBitReader`, enabling bits reading capabilities.
30-
Current `offset` value in `byteReader` is preserved.
45+
Converts a `ByteReader` instance into `LsbBitReader`, enabling bit reading capabilities. Current `offset` value of
46+
`byteReader` is preserved.
3147
*/
3248
public init(_ byteReader: ByteReader) {
3349
self.currentByte = byteReader.offset < byteReader.data.endIndex ? byteReader.data[byteReader.offset] : 0
3450
super.init(data: byteReader.data)
3551
self.offset = byteReader.offset
3652
}
3753

38-
/// True, if reader's BIT pointer is aligned with the BYTE border.
39-
public var isAligned: Bool {
40-
return self.bitMask == 1
41-
}
42-
4354
/**
4455
Reads bit and returns it, advancing by one BIT position.
4556

0 commit comments

Comments
 (0)