Skip to content

Commit 3b5f072

Browse files
committed
Merge branch 'develop'
2 parents b2e9b84 + 27b63d1 commit 3b5f072

14 files changed

Lines changed: 183 additions & 101 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.0
6+
module_version: 1.0.1
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.0
10+
github_file_prefix: https://github.com/tsolomko/BitByteData/tree/1.0.1
1111
theme: fullwidth
1212

1313
custom_categories:

.travis.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ jobs:
3232
- brew install sourcekitten
3333
- gem install -N jazzy
3434
before_deploy:
35-
# Necessary for correct SourceKitten processing.
36-
- swift build
37-
# Build Carthage archive.
38-
- carthage build --no-skip-current
39-
- carthage archive BitByteData
40-
# Generate documentation.
41-
- sourcekitten doc --spm-module BitByteData > docs.json
42-
- jazzy
35+
- >
36+
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
37+
export BEFORE_DEPLOY_RUN=1;
38+
# Necessary for correct SourceKitten processing.
39+
swift build
40+
# Build Carthage archive.
41+
carthage build --no-skip-current
42+
carthage archive BitByteData
43+
# Generate documentation.
44+
sourcekitten doc --spm-module BitByteData > docs.json
45+
jazzy
46+
fi
4347
deploy:
4448
- provider: releases
4549
skip_cleanup: true

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.0"
4+
s.version = "1.0.1"
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.0</string>
18+
<string>1.0.1</string>
1919
<key>CFBundleVersion</key>
20-
<string>4</string>
20+
<string>5</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.0</string>
18+
<string>1.0.1</string>
1919
<key>CFBundleVersion</key>
20-
<string>4</string>
20+
<string>5</string>
2121
</dict>
2222
</plist>

BitByteData.xcodeproj/project.pbxproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@
7676
06F065561FFAEA1F00312A82 /* Sources */ = {
7777
isa = PBXGroup;
7878
children = (
79-
06F065571FFAEA1F00312A82 /* LsbBitReader.swift */,
80-
06F065581FFAEA1F00312A82 /* BitReader.swift */,
79+
06F0655B1FFAEA1F00312A82 /* Extensions.swift */,
8180
06F065591FFAEA1F00312A82 /* ByteReader.swift */,
81+
06F065581FFAEA1F00312A82 /* BitReader.swift */,
82+
06F065571FFAEA1F00312A82 /* LsbBitReader.swift */,
8283
06F0655A1FFAEA1F00312A82 /* MsbBitReader.swift */,
83-
06F0655B1FFAEA1F00312A82 /* Extensions.swift */,
84-
06F0655C1FFAEA1F00312A82 /* MsbBitWriter.swift */,
8584
06F0655D1FFAEA1F00312A82 /* BitWriter.swift */,
8685
06F0655E1FFAEA1F00312A82 /* LsbBitWriter.swift */,
86+
06F0655C1FFAEA1F00312A82 /* MsbBitWriter.swift */,
8787
);
8888
path = Sources;
8989
sourceTree = "<group>";
@@ -100,11 +100,11 @@
100100
06F065611FFAEA1F00312A82 /* BitByteDataTests */ = {
101101
isa = PBXGroup;
102102
children = (
103-
06F065621FFAEA1F00312A82 /* MsbBitWriterTests.swift */,
103+
06F065661FFAEA1F00312A82 /* ByteReaderTests.swift */,
104+
06F065651FFAEA1F00312A82 /* LsbBitReaderTests.swift */,
104105
06F065631FFAEA1F00312A82 /* MsbBitReaderTests.swift */,
105106
06F065641FFAEA1F00312A82 /* LsbBitWriterTests.swift */,
106-
06F065651FFAEA1F00312A82 /* LsbBitReaderTests.swift */,
107-
06F065661FFAEA1F00312A82 /* ByteReaderTests.swift */,
107+
06F065621FFAEA1F00312A82 /* MsbBitWriterTests.swift */,
108108
);
109109
path = BitByteDataTests;
110110
sourceTree = "<group>";
@@ -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 = 4;
251+
CURRENT_PROJECT_VERSION = 5;
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 = 4;
293+
CURRENT_PROJECT_VERSION = 5;
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 = 4;
321+
DYLIB_CURRENT_VERSION = 5;
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 = 4;
340+
DYLIB_CURRENT_VERSION = 5;
341341
DYLIB_INSTALL_NAME_BASE = "@rpath";
342342
INFOPLIST_FILE = BitByteData.xcodeproj/BitByteData.plist;
343343
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

3-
## v1.0.0
3+
## 1.0.1
4+
5+
- Increased performance of `bit()`, `bits(count:)` and `int(fromBits:)` functions for both `LsbBitReader` and `MsbBitReader`.
6+
- More consistent behaviour (precondition failures) for situtations when there is not enough data left.
7+
- Small updates to documentation.
8+
9+
## 1.0.0
410

511
- `ByteReader` class for reading bytes.
612
- `BitReader` protocol, `LsbBitReader` and `MsbBitReader` classes for reading bits (and bytes).

Sources/BitReader.swift

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

14-
/// Creates an instance for reading `data`.
14+
/// Creates an instance for reading bits (and bytes) from `data`.
1515
init(data: Data)
1616

1717
/// Reads bit and returns it, advancing by one BIT position.
@@ -44,23 +44,3 @@ public protocol BitReader: class {
4444
func uint16() -> UInt16
4545

4646
}
47-
48-
extension BitReader {
49-
50-
/**
51-
- Warning: Doesn't check if there is any data left.
52-
*/
53-
public func bits(count: Int) -> [UInt8] {
54-
guard count > 0
55-
else { return [] }
56-
57-
var array = [UInt8]()
58-
array.reserveCapacity(count)
59-
for _ in 0..<count {
60-
array.append(self.bit())
61-
}
62-
63-
return array
64-
}
65-
66-
}

Sources/BitWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public protocol BitWriter {
1414
/// True, if writer's BIT pointer is aligned with the BYTE border.
1515
var isAligned: Bool { get }
1616

17-
/// Creates an instance for writing.
17+
/// Creates an instance for writing bits (and bytes).
1818
init()
1919

2020
/// Writes `bit`, advancing by one BIT position.

Sources/ByteReader.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ByteReader {
2727
return self.data.endIndex <= self.offset
2828
}
2929

30-
/// Creates an instance for reading `data`.
30+
/// Creates an instance for reading bytes from `data`.
3131
public init(data: Data) {
3232
self.size = data.count
3333
self.data = data
@@ -37,21 +37,25 @@ public class ByteReader {
3737
/**
3838
Reads byte and returns it, advancing by one position.
3939

40-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
41-
to check if the end is reached.
40+
- Precondition: There MUST be enough data left.
4241
*/
4342
public func byte() -> UInt8 {
43+
precondition(self.offset < self.size)
4444
self.offset += 1
4545
return self.data[self.offset - 1]
4646
}
4747

4848
/**
4949
Reads `count` bytes and returns them as an array of `UInt8`, advancing by `count` positions.
5050

51-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
52-
to check if the end is reached.
51+
- Precondition: Parameter `count` MUST not be less than 0.
52+
- Precondition: There MUST be enough data left.
5353
*/
5454
public func bytes(count: Int) -> [UInt8] {
55+
precondition(count >= 0)
56+
guard count > 0
57+
else { return [] }
58+
precondition(self.offset + count <= self.size)
5559
let result = self.data[self.offset..<self.offset + count].toArray(type: UInt8.self, count: count)
5660
self.offset += count
5761
return result
@@ -60,10 +64,10 @@ public class ByteReader {
6064
/**
6165
Reads 8 bytes and returns them as a `UInt64` number, advancing by 8 positions.
6266

63-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
64-
to check if the end is reached.
67+
- Precondition: There MUST be enough data left.
6568
*/
6669
public func uint64() -> UInt64 {
70+
precondition(self.offset + 8 <= self.size)
6771
let result = self.data[self.offset..<self.offset + 8].to(type: UInt64.self)
6872
self.offset += 8
6973
return result
@@ -72,10 +76,10 @@ public class ByteReader {
7276
/**
7377
Reads 4 bytes and returns them as a `UInt32` number, advancing by 4 positions.
7478

75-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
76-
to check if the end is reached.
79+
- Precondition: There MUST be enough data left.
7780
*/
7881
public func uint32() -> UInt32 {
82+
precondition(self.offset + 4 <= self.size)
7983
let result = self.data[self.offset..<self.offset + 4].to(type: UInt32.self)
8084
self.offset += 4
8185
return result
@@ -84,10 +88,10 @@ public class ByteReader {
8488
/**
8589
Reads 2 bytes and returns them as a `UInt16` number, advancing by 2 positions.
8690

87-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
88-
to check if the end is reached.
91+
- Precondition: There MUST be enough data left.
8992
*/
9093
public func uint16() -> UInt16 {
94+
precondition(self.offset + 2 <= self.size)
9195
let result = self.data[self.offset..<self.offset + 2].to(type: UInt16.self)
9296
self.offset += 2
9397
return result

0 commit comments

Comments
 (0)