Skip to main content

Module bits

Module bits 

Source
Expand description

MSB-first bit cursor over a byte slice.

CCSDS packets are bit-packed big-endian: a field starts at an arbitrary bit offset and runs most-significant bit first, straddling byte boundaries freely. Everything the decoder reads goes through BitCursor.

§The 9-byte case

A 64-bit field at a non-zero bit offset spans nine bytes. The obvious implementation — load eight bytes and shift — silently truncates it. Every read here goes through a u128 accumulator, which covers the widest possible span (7 offset bits + 64 width) with room to spare. The property tests deliberately generate that case.

§No panics

Every out-of-range read returns BitError. A corrupt or hostile packet must never bring down a decoder that is processing a live downlink.

Structs§

BitCursor
A big-endian, MSB-first bit reader.

Enums§

BitError
Reading past the end of the data, or asking for more bits than fit in the result.

Functions§

ones_complement
Reinterprets an unsigned field as ones’ complement.
sign_magnitude
Reinterprets an unsigned field as sign-magnitude: top bit is the sign, rest the magnitude.
swap_byte_order
Reverses the byte order of a field, for leastSignificantByteFirst encodings.
twos_complement
Reinterprets an unsigned field of width bits as a signed integer.
twos_complement_unmasked
Sign extension for the one case where the value can be wider than the field it came from.