Add fixed-point codecs#1568
Conversation
|
BundleMonFiles updated (4)
Unchanged files (143)
Total files change +3.98KB +0.77% Final result: ✅ View report in BundleMon website ➡️ |
|
Documentation Preview: https://kit-docs-7aa2o4lfp-anza-tech.vercel.app |
08d6604 to
9a22f6a
Compare
dec9bf6 to
8e377fb
Compare
9a22f6a to
a6469c7
Compare
8e377fb to
89cd89f
Compare
89cd89f to
f97f875
Compare
a6469c7 to
82550ec
Compare
mcintyre94
left a comment
There was a problem hiding this comment.
Nice, this implementation looks great!
82550ec to
a49dee0
Compare
2031a98 to
ec8d8d1
Compare
a49dee0 to
6f5b036
Compare
Merge activity
|
6f5b036 to
e95504c
Compare
ec8d8d1 to
947f588
Compare
e95504c to
f15d69d
Compare
947f588 to
9d7fc99
Compare
This PR adds `getBinaryFixedPointCodec`, `getDecimalFixedPointCodec`, and their encoder/decoder counterparts to `@solana/fixed-points`. Each factory takes a signedness, total bits, scale, and an optional `FixedPointCodecConfig` (`{ endian?: 'le' | 'be' }`, defaults to little-endian), and produces a `FixedSizeCodec` whose byte-size literal is preserved for widths that are multiples of 8 from 8 to 256 bits. Non-byte-aligned total bits throw a `SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED` error.
The byte-level IO uses `DataView.setBigUint64`/`getBigUint64` for every 64-bit chunk, then greedily consumes the remaining 0-7 bytes with at most one `setUint32`/`setUint16` and a direct byte write. This matches `@solana/codecs-numbers` performance for common widths (u8/u16/u32/u64/u128) and stays efficient for non-standard widths like u24/u40/u72. The read path uses `toArrayBuffer` from `@solana/codecs-core` so it works in environments where `SharedArrayBuffer` is undefined (React Native, non-isolated browsers). In the future, the number codecs in `@solana/codecs-numbers` could delegate to these more generic fixed-point codecs under the hood.
f15d69d to
6d87c49
Compare
| // Full 64-bit chunks. LE lays chunks low-to-high; BE lays higher-order | ||
| // chunks at lower memory addresses. | ||
| for (let c = 0; c < fullChunks; c++) { | ||
| const chunk = (unsigned >> BigInt(c * 64)) & MASK_64; |
| let consumed = 0; | ||
|
|
||
| if (residual - consumed >= 4) { | ||
| const chunk = Number((residualChunk >> BigInt(consumed * 8)) & MASK_32); |
| consumed += 4; | ||
| } | ||
| if (residual - consumed >= 2) { | ||
| const chunk = Number((residualChunk >> BigInt(consumed * 8)) & MASK_16); |
| consumed += 2; | ||
| } | ||
| if (residual - consumed >= 1) { | ||
| const chunk = Number((residualChunk >> BigInt(consumed * 8)) & MASK_8); |
|
🔎💬 Inkeep AI search and chat service is syncing content for source 'Solana Kit Docs' |

This PR adds
getBinaryFixedPointCodec,getDecimalFixedPointCodec, and their encoder/decoder counterparts to@solana/fixed-points. Each factory takes a signedness, total bits, scale, and an optionalFixedPointCodecConfig({ endian?: 'le' | 'be' }, defaults to little-endian), and produces aFixedSizeCodecwhose byte-size literal is preserved for widths that are multiples of 8 from 8 to 256 bits. Non-byte-aligned total bits throw aSOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNEDerror.The byte-level IO uses
DataView.setBigUint64/getBigUint64for every 64-bit chunk, then greedily consumes the remaining 0-7 bytes with at most onesetUint32/setUint16and a direct byte write. This matches@solana/codecs-numbersperformance for common widths (u8/u16/u32/u64/u128) and stays efficient for non-standard widths like u24/u40/u72. The read path usestoArrayBufferfrom@solana/codecs-coreso it works in environments whereSharedArrayBufferis undefined (React Native, non-isolated browsers). In the future, the number codecs in@solana/codecs-numberscould delegate to these more generic fixed-point codecs under the hood.