def bits.read

gralha-bytes@0.1.0.1 · bytes.bend:116

import gralha-bytes@0.1.0.1/bytes.bend as Bytes
import Base

116def bits.read(stream: BitStream, +count: U32) -> BitRead:
117  BitStream{data, position, limit, valid} = stream
118  +src = data
119  +pos = position
120  +end = limit
121  +at = (pos / 8 : U32)
122  +word = (bytes.get(src, at) + bytes.get(src, U32.inc(at)) * 256 + bytes.get(src, (at + 2 : U32)) * 65536 : U32)
123  BitRead{U32.and(U32.shrn(word, U32.to_nat(U32.mod(pos, 8))), (U32.shln(1, U32.to_nat(count)) - 1 : U32)), BitStream{src, (pos + count : U32), end, valid && U32.is_le((pos + count : U32), end)}}

Uses (16)

Used by (9)