moddef.codec.bytes module

Register/byte assembly honoring byte order within a word and word order across words (spec §9). Mirrors go/codec and the TS/Rust byte helpers.

moddef.codec.bytes.assemble(regs: Sequence[int], byte_big: bool, word_big: bool) bytes[source]

Normalize registers into a big-endian byte stream.

moddef.codec.bytes.decode_uint(b: bytes) int[source]

Big-endian unsigned integer of the byte stream (arbitrary width).

moddef.codec.bytes.last_n(b: bytes, n: int) bytes[source]
moddef.codec.bytes.mask_for(bits: int) int[source]
moddef.codec.bytes.pad_bytes(b: bytes, total: int) bytes[source]

Zero-pad (or truncate) to exactly total bytes.

moddef.codec.bytes.sign_extend(v: int, bits: int) int[source]
moddef.codec.bytes.words_from_bytes(b: bytes, byte_big: bool, word_big: bool) list[int][source]

Write a normalized big-endian byte stream into registers.

moddef.codec.bytes.words_from_uint(raw: int, n_words: int, byte_big: bool, word_big: bool) list[int][source]

Split an unsigned integer into registers (inverse of assemble+decode).