aboutsummaryrefslogtreecommitdiff
path: root/src/bitreader.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitreader.nim')
-rw-r--r--src/bitreader.nim11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/bitreader.nim b/src/bitreader.nim
index 7afb13d..baa8bf8 100644
--- a/src/bitreader.nim
+++ b/src/bitreader.nim
@@ -48,9 +48,10 @@ proc readBits*[T: SomeUnsignedInt](bitReader: BitReader, bits: int, to: typedesc
48proc readBool*(bitReader: BitReader): bool = 48proc readBool*(bitReader: BitReader): bool =
49 bitReader.readBits(1, uint8) != 0 49 bitReader.readBits(1, uint8) != 0
50 50
51proc readSeq*[T: SomeUnsignedInt](bitReader: BitReader, bitLength: int, to: typedesc[T]): tuple[bitLength: int, data: seq[T]] = 51proc readSeq*[T: SomeUnsignedInt](bitReader: BitReader, maxBitLength: int, to: typedesc[T]): tuple[bitLength: int, data: seq[T]] =
52 result = (0, newSeqOfCap[T](bitLength /^ (sizeof(T) * wordBitLength))) 52 result = (0, newSeqOfCap[T](maxBitLength /^ (sizeof(T) * wordBitLength)))
53 for _, chunkBitLength in chunks(bitLength, T): 53 for _, chunkBitLength in chunks(maxBitLength, T):
54 if bitReader.atEnd(): return 54 if bitReader.atEnd(): return
55 result.bitLength += chunkBitLength 55 let bitsToRead = if bitReader.stream.atEnd(): sizeof(T) * wordBitLength - bitReader.bitOffset else: chunkBitLength
56 result.data.add(bitReader.readBits(chunkBitLength, T)) 56 result.bitLength += bitsToRead
57 result.data.add(bitReader.readBits(bitsToRead, T))