55
66import Foundation
77
8- /// A type that contains functions for reading `Data` byte-by-byte in the Little endian order.
8+ /// A type that contains functions for reading `Data` byte-by-byte in the Little Endian order.
99public final class LittleEndianByteReader : ByteReader {
1010
1111 /// Size of the `data` (in bytes).
@@ -14,31 +14,31 @@ public final class LittleEndianByteReader: ByteReader {
1414 /// Data which is being read.
1515 public let data : Data
1616
17- /// Offset to the byte in `data` which will be read next.
17+ /// Offset to a byte in the `data` which will be read next.
1818 public var offset : Int
1919
20- /// Creates an instance for reading bytes from `data`.
20+ /// Creates an instance for reading bytes from the `data`.
2121 public init ( data: Data ) {
2222 self . size = data. count
2323 self . data = data
2424 self . offset = data. startIndex
2525 }
2626
2727 /**
28- Reads byte and returns it, advancing by one position.
28+ Reads a byte and returns it, advancing by one position.
2929
30- - Precondition: There MUST be enough data left.
30+ - Precondition: There must be enough bytes left.
3131 */
3232 public func byte( ) -> UInt8 {
3333 defer { offset += 1 }
3434 return data [ offset]
3535 }
3636
3737 /**
38- Reads `count` bytes and returns them as an array of ` UInt8` , advancing by `count` positions.
38+ Reads `count` bytes and returns them as a `[ UInt8]` array , advancing by `count` positions.
3939
40- - Precondition: Parameter `count` MUST not be less than 0 .
41- - Precondition: There MUST be enough data left.
40+ - Precondition: Parameter `count` must be non-negative .
41+ - Precondition: There must be enough bytes left.
4242 */
4343 public func bytes( count: Int ) -> [ UInt8 ] {
4444 precondition ( count >= 0 )
@@ -49,21 +49,20 @@ public final class LittleEndianByteReader: ByteReader {
4949 /**
5050 Reads 8 bytes and returns them as a `UInt64` number, advancing by 8 positions.
5151
52- - Precondition: There MUST be enough data left.
52+ - Precondition: There must be enough bytes left.
5353 */
5454 public func uint64( ) -> UInt64 {
5555 defer { offset += 8 }
5656 return data [ offset..< offset + 8 ] . toU64 ( )
5757 }
5858
5959 /**
60- Reads `fromBytes` bytes and returns them as an `UInt64` number, advancing by `fromBytes` positions.
60+ Reads `fromBytes` bytes and returns them as a `UInt64` number, advancing by `fromBytes` positions.
6161
62- - Note: If it is known that `fromBytes` is exactly 8, then consider using `uint64()` function (without argument),
63- since it has better performance in this situation.
64- - Precondition: Parameter `fromBits` MUST be from `0..8` range, i.e. it MUST not exceed maximum possible amount of
65- bytes that `UInt64` type can represent.
66- - Precondition: There MUST be enough data left.
62+ - Note: If it is known that the `fromBytes` is exactly 8 then consider using the `uint64()` function (without an
63+ argument), since it may provide better performance.
64+ - Precondition: Parameter `fromBytes` must be in the `0...8` range.
65+ - Precondition: There must be enough bytes left.
6766 */
6867 public func uint64( fromBytes count: Int ) -> UInt64 {
6968 precondition ( 0 ... 8 ~= count)
@@ -78,21 +77,20 @@ public final class LittleEndianByteReader: ByteReader {
7877 /**
7978 Reads 4 bytes and returns them as a `UInt32` number, advancing by 4 positions.
8079
81- - Precondition: There MUST be enough data left.
80+ - Precondition: There must be enough bytes left.
8281 */
8382 public func uint32( ) -> UInt32 {
8483 defer { offset += 4 }
8584 return data [ offset..< offset + 4 ] . toU32 ( )
8685 }
8786
8887 /**
89- Reads `fromBytes` bytes and returns them as an `UInt32` number, advancing by `fromBytes` positions.
88+ Reads `fromBytes` bytes and returns them as a `UInt32` number, advancing by `fromBytes` positions.
9089
91- - Note: If it is known that `fromBytes` is exactly 4, then consider using `uint32()` function (without argument),
92- since it has better performance in this situation.
93- - Precondition: Parameter `fromBits` MUST be from `0..4` range, i.e. it MUST not exceed maximum possible amount of
94- bytes that `UInt32` type can represent.
95- - Precondition: There MUST be enough data left.
90+ - Note: If it is known that the `fromBytes` is exactly 4 then consider using the `uint32()` function (without an
91+ argument), since it may provide better performance.
92+ - Precondition: Parameter `fromBytes` must be in the `0...4` range.
93+ - Precondition: There must be enough bytes left.
9694 */
9795 public func uint32( fromBytes count: Int ) -> UInt32 {
9896 precondition ( 0 ... 4 ~= count)
@@ -107,21 +105,20 @@ public final class LittleEndianByteReader: ByteReader {
107105 /**
108106 Reads 2 bytes and returns them as a `UInt16` number, advancing by 2 positions.
109107
110- - Precondition: There MUST be enough data left.
108+ - Precondition: There must be enough bytes left.
111109 */
112110 public func uint16( ) -> UInt16 {
113111 defer { offset += 2 }
114112 return data [ offset..< offset + 2 ] . toU16 ( )
115113 }
116114
117115 /**
118- Reads `fromBytes` bytes and returns them as an `UInt16` number, advancing by `fromBytes` positions.
116+ Reads `fromBytes` bytes and returns them as a `UInt16` number, advancing by `fromBytes` positions.
119117
120- - Note: If it is known that `fromBytes` is exactly 2, then consider using `uint16()` function (without argument),
121- since it has better performance in this situation.
122- - Precondition: Parameter `fromBits` MUST be from `0..2` range, i.e. it MUST not exceed maximum possible amount of
123- bytes that `UInt16` type can represent.
124- - Precondition: There MUST be enough data left.
118+ - Note: If it is known that the `fromBytes` is exactly 2 then consider using the `uint16()` function (without an
119+ argument), since it may provide better performance.
120+ - Precondition: Parameter `fromBytes` must be in the `0...2` range.
121+ - Precondition: There must be enough bytes left.
125122 */
126123 public func uint16( fromBytes count: Int ) -> UInt16 {
127124 precondition ( 0 ... 2 ~= count)
0 commit comments