@@ -257,13 +257,7 @@ public final class LsbBitReader: ByteReader, BitReader {
257257 public override var offset : Int {
258258 didSet {
259259 if !self . isFinished {
260- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
261- { ( data: Data , offset: Int , currentByte: inout UInt8 ) in
262- currentByte = data [ offset]
263- } ( self . data, self . offset, & self . currentByte)
264- #else
265- self . currentByte = self . data [ self . offset]
266- #endif
260+ self . currentByte = self . data [ self . offset]
267261 }
268262 }
269263 }
@@ -275,19 +269,8 @@ public final class LsbBitReader: ByteReader, BitReader {
275269 - Precondition: There MUST be enough data left.
276270 */
277271 public override func byte( ) -> UInt8 {
278- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
279- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt8 in
280- precondition ( bitMask == 1 , " BitReader is not aligned. " )
281- precondition ( offset < data. endIndex)
282- defer { offset += 1 }
283- return data [ offset]
284- } ( self . data, & self . offset, self . bitMask)
285- #else
286- precondition ( bitMask == 1 , " BitReader is not aligned. " )
287- precondition ( self . offset < self . data. endIndex)
288- defer { self . offset += 1 }
289- return self . data [ self . offset]
290- #endif
272+ precondition ( isAligned, " BitReader is not aligned. " )
273+ return super. byte ( )
291274 }
292275
293276 /**
@@ -297,19 +280,8 @@ public final class LsbBitReader: ByteReader, BitReader {
297280 - Precondition: There MUST be enough data left.
298281 */
299282 public override func bytes( count: Int ) -> [ UInt8 ] {
300- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
301- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> [ UInt8 ] in
302- precondition ( bitMask == 1 , " BitReader is not aligned. " )
303- precondition ( data. endIndex - offset >= count)
304- defer { offset += count }
305- return data [ offset..< offset + count] . toArray ( type: UInt8 . self, count: count)
306- } ( self . data, & self . offset, self . bitMask)
307- #else
308- precondition ( bitMask == 1 , " BitReader is not aligned. " )
309- precondition ( bytesLeft >= count)
310- defer { self . offset += count }
311- return self . data [ self . offset..< self . offset + count] . toArray ( type: UInt8 . self, count: count)
312- #endif
283+ precondition ( isAligned, " BitReader is not aligned. " )
284+ return super. bytes ( count: count)
313285 }
314286
315287 /**
@@ -320,28 +292,8 @@ public final class LsbBitReader: ByteReader, BitReader {
320292 - Precondition: There MUST be enough data left.
321293 */
322294 public override func int( fromBytes count: Int ) -> Int {
323- precondition ( count >= 0 )
324- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
325- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> Int in
326- precondition ( bitMask == 1 , " BitReader is not aligned. " )
327- precondition ( data. endIndex - offset >= count)
328- var result = 0
329- for i in 0 ..< count {
330- result += Int ( truncatingIfNeeded: data [ offset] ) << ( 8 * i)
331- offset += 1
332- }
333- return result
334- } ( self . data, & self . offset, self . bitMask)
335- #else
336- precondition ( bitMask == 1 , " BitReader is not aligned. " )
337- precondition ( bytesLeft >= count)
338- var result = 0
339- for i in 0 ..< count {
340- result += Int ( truncatingIfNeeded: self . data [ self . offset] ) << ( 8 * i)
341- self . offset += 1
342- }
343- return result
344- #endif
295+ precondition ( isAligned, " BitReader is not aligned. " )
296+ return super. int ( fromBytes: count)
345297 }
346298
347299 /**
@@ -351,19 +303,8 @@ public final class LsbBitReader: ByteReader, BitReader {
351303 - Precondition: There MUST be enough data left.
352304 */
353305 public override func uint64( ) -> UInt64 {
354- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
355- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt64 in
356- precondition ( bitMask == 1 , " BitReader is not aligned. " )
357- precondition ( data. endIndex - offset >= 8 )
358- defer { offset += 8 }
359- return data [ offset..< offset + 8 ] . to ( type: UInt64 . self)
360- } ( self . data, & self . offset, self . bitMask)
361- #else
362- precondition ( bitMask == 1 , " BitReader is not aligned. " )
363- precondition ( bytesLeft >= 8 )
364- defer { self . offset += 8 }
365- return self . data [ self . offset..< self . offset + 8 ] . to ( type: UInt64 . self)
366- #endif
306+ precondition ( isAligned, " BitReader is not aligned. " )
307+ return super. uint64 ( )
367308 }
368309
369310 /**
@@ -374,28 +315,8 @@ public final class LsbBitReader: ByteReader, BitReader {
374315 - Precondition: There MUST be enough data left.
375316 */
376317 public override func uint64( fromBytes count: Int ) -> UInt64 {
377- precondition ( 0 ... 8 ~= count)
378- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
379- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt64 in
380- precondition ( bitMask == 1 , " BitReader is not aligned. " )
381- precondition ( data. endIndex - offset >= count)
382- var result = 0 as UInt64
383- for i in 0 ..< count {
384- result += UInt64 ( truncatingIfNeeded: data [ offset] ) << ( 8 * i)
385- offset += 1
386- }
387- return result
388- } ( self . data, & self . offset, self . bitMask)
389- #else
390- precondition ( bitMask == 1 , " BitReader is not aligned. " )
391- precondition ( bytesLeft >= count)
392- var result = 0 as UInt64
393- for i in 0 ..< count {
394- result += UInt64 ( truncatingIfNeeded: self . data [ self . offset] ) << ( 8 * i)
395- self . offset += 1
396- }
397- return result
398- #endif
318+ precondition ( isAligned, " BitReader is not aligned. " )
319+ return super. uint64 ( fromBytes: count)
399320 }
400321
401322 /**
@@ -405,19 +326,8 @@ public final class LsbBitReader: ByteReader, BitReader {
405326 - Precondition: There MUST be enough data left.
406327 */
407328 public override func uint32( ) -> UInt32 {
408- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
409- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt32 in
410- precondition ( bitMask == 1 , " BitReader is not aligned. " )
411- precondition ( data. endIndex - offset >= 4 )
412- defer { offset += 4 }
413- return data [ offset..< offset + 4 ] . to ( type: UInt32 . self)
414- } ( self . data, & self . offset, self . bitMask)
415- #else
416- precondition ( bitMask == 1 , " BitReader is not aligned. " )
417- precondition ( bytesLeft >= 4 )
418- defer { self . offset += 4 }
419- return self . data [ self . offset..< self . offset + 4 ] . to ( type: UInt32 . self)
420- #endif
329+ precondition ( isAligned, " BitReader is not aligned. " )
330+ return super. uint32 ( )
421331 }
422332
423333 /**
@@ -428,28 +338,8 @@ public final class LsbBitReader: ByteReader, BitReader {
428338 - Precondition: There MUST be enough data left.
429339 */
430340 public override func uint32( fromBytes count: Int ) -> UInt32 {
431- precondition ( 0 ... 4 ~= count)
432- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
433- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt32 in
434- precondition ( bitMask == 1 , " BitReader is not aligned. " )
435- precondition ( data. endIndex - offset >= count)
436- var result = 0 as UInt32
437- for i in 0 ..< count {
438- result += UInt32 ( truncatingIfNeeded: data [ offset] ) << ( 8 * i)
439- offset += 1
440- }
441- return result
442- } ( self . data, & self . offset, self . bitMask)
443- #else
444- precondition ( bitMask == 1 , " BitReader is not aligned. " )
445- precondition ( bytesLeft >= count)
446- var result = 0 as UInt32
447- for i in 0 ..< count {
448- result += UInt32 ( truncatingIfNeeded: self . data [ self . offset] ) << ( 8 * i)
449- self . offset += 1
450- }
451- return result
452- #endif
341+ precondition ( isAligned, " BitReader is not aligned. " )
342+ return super. uint32 ( fromBytes: count)
453343 }
454344
455345 /**
@@ -459,19 +349,8 @@ public final class LsbBitReader: ByteReader, BitReader {
459349 - Precondition: There MUST be enough data left.
460350 */
461351 public override func uint16( ) -> UInt16 {
462- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
463- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt16 in
464- precondition ( bitMask == 1 , " BitReader is not aligned. " )
465- precondition ( data. endIndex - offset >= 2 )
466- defer { offset += 2 }
467- return data [ offset..< offset + 2 ] . to ( type: UInt16 . self)
468- } ( self . data, & self . offset, self . bitMask)
469- #else
470- precondition ( bitMask == 1 , " BitReader is not aligned. " )
471- precondition ( bytesLeft >= 2 )
472- defer { self . offset += 2 }
473- return self . data [ self . offset..< self . offset + 2 ] . to ( type: UInt16 . self)
474- #endif
352+ precondition ( isAligned, " BitReader is not aligned. " )
353+ return super. uint16 ( )
475354 }
476355
477356 /**
@@ -482,28 +361,8 @@ public final class LsbBitReader: ByteReader, BitReader {
482361 - Precondition: There MUST be enough data left.
483362 */
484363 public override func uint16( fromBytes count: Int ) -> UInt16 {
485- precondition ( 0 ... 2 ~= count)
486- #if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
487- return { ( data: Data , offset: inout Int , bitMask: UInt8 ) -> UInt16 in
488- precondition ( bitMask == 1 , " BitReader is not aligned. " )
489- precondition ( data. endIndex - offset >= count)
490- var result = 0 as UInt16
491- for i in 0 ..< count {
492- result += UInt16 ( truncatingIfNeeded: data [ offset] ) << ( 8 * i)
493- offset += 1
494- }
495- return result
496- } ( self . data, & self . offset, self . bitMask)
497- #else
498- precondition ( bitMask == 1 , " BitReader is not aligned. " )
499- precondition ( bytesLeft >= count)
500- var result = 0 as UInt16
501- for i in 0 ..< count {
502- result += UInt16 ( truncatingIfNeeded: self . data [ self . offset] ) << ( 8 * i)
503- self . offset += 1
504- }
505- return result
506- #endif
364+ precondition ( isAligned, " BitReader is not aligned. " )
365+ return super. uint16 ( fromBytes: count)
507366 }
508367
509368}
0 commit comments