feat(moq-net): encode Hop ID as fixed-width 64-bit on lite-05#1788
Merged
Conversation
Implements moq-dev/drafts#33 for moq-lite-05. Hop IDs are randomly assigned, so a varint would almost never be shorter than its fixed-width equivalent, and switching to a fixed-width 64-bit integer also recovers the 2 bits a 62-bit varint would have cost. Applies to the three moq-lite wire fields that carry Hop ID values, gated to lite-05+ so lite-04 and earlier keep the varint: - ANNOUNCE_OK Hop ID - ANNOUNCE Hop ID list - ANNOUNCE_INTEREST Exclude Hop Rust: new Version::hops_fixed_width() gate (older versions listed so future versions default forward). Origin's Encode/Decode is now concrete over lite::Version so it can branch between fixed-width and varint; the fixed-width path carries the full 64-bit space (no 62-bit cap). exclude_hop routes through Origin to share the branch. JS mirror: Reader/Writer.u64() fixed-width helpers, hopsFixedWidth() predicate, OriginSchema widened to 64 bits. randomOrigin stays masked to 62 bits since the same id must still varint-encode on a negotiated lite-04 session. The moqt relay-hops half of the draft PR (HOP_PATH / EXCLUDE_HOP KVP parameters) is not implemented anywhere in this repo, so there is nothing to change there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kixelated
commented
Jun 19, 2026
| Ok(Self { id: r.get_u64() }) | ||
| } else { | ||
| let id = u64::decode(r, version)?; | ||
| if id >= 1u64 << 62 { |
Collaborator
Author
There was a problem hiding this comment.
This should be impossible?
Collaborator
Author
There was a problem hiding this comment.
Right, that was dead code. A lite Version varint decodes via decode_quic, which masks the top 2 bits off, so the value already caps at 2^62-1 and the check could never fire. Dropped it in 562a96f. (Written by Claude)
A lite Version varint decodes via decode_quic, which masks to 62 bits, so the `id >= 1 << 62` overflow check could never fire. Remove the dead check. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Implements moq-dev/drafts#33 ("Encode Hop ID as fixed-width 64-bit integer") for moq-lite-05.
Hop IDs are randomly assigned, so a variable-length integer would almost never be shorter than its fixed-width equivalent. Switching to a fixed-width big-endian 64-bit integer also recovers the 2 bits a 62-bit varint would have cost (the value can now use the full 64-bit space).
Summary
Applies to the three moq-lite wire fields that carry Hop ID values, gated to lite-05+ so lite-04 and earlier keep the varint:
Hop ID→(64)Hop IDlist →(64)Exclude Hop→(64)Rust (
rs/moq-net)Version::hops_fixed_width()predicate. Older versions are listed explicitly so future versions default forward (per the version-matching convention).Origin'sEncode/Decodeare now concrete overlite::Versionso they can branch: the fixed-width path uses big-endianput_u64/get_u64and carries the full 64-bit space (no 62-bit cap); older versions keep the varint + cap.exclude_hoproutes throughOriginto share the same branch.JS mirror (
js/net)Reader.u64()/Writer.u64()fixed-width helpers (+setBigUint64).hopsFixedWidth(version)predicate mirroring Rust.OriginSchemawidened 62 → 64 bits.randomOrigindeliberately stays masked to 62 bits, because the same id must still varint-encode if a session negotiates lite-04.Not included
The moqt relay-hops half of the draft PR (
HOP_PATHlist of 8-byte entries,EXCLUDE_HOPtype0x40B58→0x40B59length-prefixed) targets the moq-transport KVP parameters, which are not implemented anywhere in this repo yet, so there is nothing to change.Branch targeting
Targets dev per the branch-targeting rules (wire-protocol change under
rs/moq-net).Test plan
cargo test -p moq-net(389 pass), incl. new tests: fullu64::MAXorigin round-trip, fixed-width byte count,exclude_hopround-trip across[0, 7, 1<<53, u64::MAX].bun testinjs/net(180 pass), incl. newu64fixed-width stream test; integration test exercises the AnnounceOk + hops flow end-to-end.cargo fmt --check(via nix), biome, andtsc --noEmitall clean.(Written by Claude)