bsatn: a pure-Lua BSATN primitive codec #82
No reviewers
Labels
No labels
area:defold
area:docs
area:infra
area:protocol
area:testing
kind:bug
kind:chore
phase:breadth
phase:core
phase:hardening
phase:slice
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
yuris/spacetimedb-defold!82
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bsatn-phase1-codec"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Phase 1 of #9. New module
stdb/bsatn.luaplus its unit suite. Nothing else in the SDK requires it yet, so this lands inert.Pure arithmetic rather than
require("bit"): the unit-test host is plain Lua 5.1 with nobitmodule, and one implementation that runs both there and in Defold beats two that agree by inspection.Value surface matches what
protocol.luaalready hands out: u64/i64 on a double (exact to 2^53, rounding above), 128-bit as exact decimal digit strings, 256-bit as minimal-width hex including the-0x8000…case.Verified:
lua dev/test/runner.luaon this branch alone: 9 passed, 0 failed. Float bit patterns were cross-checked against node'sBuffer.writeDoubleLE, not against this codec. Two deliberate mutants were injected and both were killed by the suite.The v2 message schema is served only in BSATN, so speaking it at all starts with a codec. Pure arithmetic rather than require("bit"): the unit-test host is plain Lua 5.1 with no bit module, and one implementation that runs in both places beats two that agree by inspection. u64/i64 land on a double, exact to 2^53 and rounding above, which is the surface the v1 JSON path already documents. 128-bit values become exact decimal digit strings and 256-bit ones minimal-width hex, both matching what protocol.lua already hands out.Review round: clean, merge as-is
Reviewed for codec correctness and for hostile input. No findings. Nothing in this PR was changed
as a result of the review.
What the review actually exercised, beyond reading:
f32/f64values round-tripped bit-exact through the writer and back throughthe reader. This is the check that matters for a hand-rolled IEEE-754 codec built on
math.ldexpand 32-bit bit ops, and it covers the cases a spot-check misses: subnormals, signed zero, the
infinities, and NaN.
hex paths checked against a second implementation rather than against themselves, so a shared bug
in the divmod-by-10 loop could not hide.
One note for the reader of this stack, so the diff is not confusing later: this PR's
stdb/bsatn.luagained two things after it was reviewed, and they landed on #83's branch, not here — a bounded
Reader:len(the fix for the array-count amplification described on #83) and the wide-type writersneeded for wide reducer arguments. Review #83 for both.
Verification state at the stack tip (
bsatn-phase5-docs): unit suite 11 passed, 0 failed;all four conformance suites PASS end to end — v1 native, v2 native, v1 HTML5, v2 HTML5 — under the
new protocol-specific gates, whose negative controls were proven non-vacuous;
stylua --check stdb dev/testclean.