fix: serialize battery_state as string to avoid precision loss in wasm bindings - #45
Open
JarrenMorris wants to merge 1 commit into
Open
fix: serialize battery_state as string to avoid precision loss in wasm bindings#45JarrenMorris wants to merge 1 commit into
JarrenMorris wants to merge 1 commit into
Conversation
…rsing step in the battery where a number was too big
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.
Summary
Background: truncated aircraftSn
The log format stores details.aircraftSn in a fixed
16-byte slot. Neweraircraft (e.g. Mavic 3 Enterprise) have
20-character serials, so the last4 characters get truncated at the source —
details.aircraftSncomes back4 characters short of the real serial.
To work around this, we added a TS-side enrichment step that pulls the full,
untruncated serial from the length-prefixed
ComponentSerialrecord instead,via
parser.records():The bug this workaround ran into
records()serializes every raw record field across the WASM boundary,including
SmartBatteryDynamic::battery_state— a bitfield that can exceed2^53, the largest integer JS can represent exactly as a
number. When thatvalue was out of range, serde-wasm-bindgen failed to serialize it,
records()threw, the
catchabove swallowed the error, anddetails.aircraftSnsilentlyfell back to the truncated 16-byte value — defeating the workaround on exactly
the logs it was meant to fix.
Fix
Map
battery_stateto aStringat parse time(#[br(map = |x: u64| x.to_string())])so the full 64-bit value survives thetrip through JS without precision loss, and
records()no longer throws forthese logs.