Add fixed-width primitive codecs (sized ints, floats, fixed)#2
Merged
Conversation
kasperisager
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the fixed-width primitive codecs, matching the JS compact-encoding wire format byte-for-byte:
uint8,uint16,uint24,uint40,uint48,uint56(N-byte little-endian).int24,int40,int48,int56(zigzag over the fixed-width uint).float32,float64(IEEE-754 little-endian viastruct).fixed(n)factory plusfixed32(32 bytes) andfixed64(64 bytes), no length prefix.Validation reuses the existing
_validate_uint(rejects values aboveMAX_SAFE_INTEGER, matching JS) plus a per-type width bound; out-of-range encodes raiseValueError, truncated decodes raiseOutOfBounds. Each family is a single parameterized codec class. Every codec has byte-exact unit tests (cross-checked against the JS reference) and a round-trip row.No new dependencies (
structis stdlib); no existing codec is changed.