Skip to content

feat(moq-net): encode Hop ID as fixed-width 64-bit on lite-05#1788

Merged
kixelated merged 2 commits into
devfrom
claude/nifty-bohr-64a3af
Jun 19, 2026
Merged

feat(moq-net): encode Hop ID as fixed-width 64-bit on lite-05#1788
kixelated merged 2 commits into
devfrom
claude/nifty-bohr-64a3af

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

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:

  • ANNOUNCE_OK Hop ID(64)
  • ANNOUNCE Hop ID list → (64)
  • ANNOUNCE_INTEREST Exclude Hop(64)

Rust (rs/moq-net)

  • New Version::hops_fixed_width() predicate. Older versions are listed explicitly so future versions default forward (per the version-matching convention).
  • Origin's Encode/Decode are now concrete over lite::Version so they can branch: the fixed-width path uses big-endian put_u64/get_u64 and carries the full 64-bit space (no 62-bit cap); older versions keep the varint + cap.
  • exclude_hop routes through Origin to share the same branch.

JS mirror (js/net)

  • Added Reader.u64() / Writer.u64() fixed-width helpers (+ setBigUint64).
  • hopsFixedWidth(version) predicate mirroring Rust.
  • OriginSchema widened 62 → 64 bits. randomOrigin deliberately 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_PATH list of 8-byte entries, EXCLUDE_HOP type 0x40B580x40B59 length-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: full u64::MAX origin round-trip, fixed-width byte count, exclude_hop round-trip across [0, 7, 1<<53, u64::MAX].
  • Full Rust workspace builds (moq-relay / moq-bench included).
  • bun test in js/net (180 pass), incl. new u64 fixed-width stream test; integration test exercises the AnnounceOk + hops flow end-to-end.
  • clippy + cargo fmt --check (via nix), biome, and tsc --noEmit all clean.

(Written by Claude)

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>
Comment thread rs/moq-net/src/model/origin.rs Outdated
Ok(Self { id: r.get_u64() })
} else {
let id = u64::decode(r, version)?;
if id >= 1u64 << 62 {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be impossible?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@kixelated kixelated enabled auto-merge (squash) June 19, 2026 02:22
@kixelated kixelated merged commit efd2164 into dev Jun 19, 2026
1 check passed
@kixelated kixelated deleted the claude/nifty-bohr-64a3af branch June 19, 2026 02:30
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.

1 participant