Skip to content

Add fixed-width primitive codecs (sized ints, floats, fixed)#2

Merged
bavulapati merged 5 commits into
mainfrom
primitives
Jul 10, 2026
Merged

Add fixed-width primitive codecs (sized ints, floats, fixed)#2
bavulapati merged 5 commits into
mainfrom
primitives

Conversation

@bavulapati

Copy link
Copy Markdown
Contributor

Adds the fixed-width primitive codecs, matching the JS compact-encoding wire format byte-for-byte:

  • Sized unsigned ints: uint8, uint16, uint24, uint40, uint48, uint56 (N-byte little-endian).
  • Sized signed ints: int24, int40, int48, int56 (zigzag over the fixed-width uint).
  • Floats: float32, float64 (IEEE-754 little-endian via struct).
  • Fixed byte blocks: fixed(n) factory plus fixed32 (32 bytes) and fixed64 (64 bytes), no length prefix.

Validation reuses the existing _validate_uint (rejects values above MAX_SAFE_INTEGER, matching JS) plus a per-type width bound; out-of-range encodes raise ValueError, truncated decodes raise OutOfBounds. 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 (struct is stdlib); no existing codec is changed.

@bavulapati bavulapati requested a review from a team July 9, 2026 18:52
@bavulapati bavulapati merged commit 502e020 into main Jul 10, 2026
7 checks passed
@bavulapati bavulapati deleted the primitives branch July 10, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants