MCPcopy Create free account
hub / github.com/GCWing/BitFun / format_token

Function format_token

src/crates/execution/tool-contracts/src/element_token.rs:280–283  ·  view source on GitHub ↗

Format `(snapshot_id, element_index)` as the canonical token string. A 4-hex-char snapshot prefix means tokens stay under 12 chars even with 4-digit indices. Snapshot ids are masked to 16 bits by [`TokenRegistry::register_snapshot`] before storage so the round trip `resolve(format_token(id, idx))` closes cleanly without truncation drift. Collision chance inside the 8-entry LRU window is 8/65536 ≈

(snapshot_id: u32, element_index: usize)

Source from the content-addressed store, hash-verified

278/// registry treats the `(pid, snapshot_id)` pair as the lookup key so a
279/// same-bits collision across pids never aliases.
280pub fn format_token(snapshot_id: u32, element_index: usize) -> String {
281 let short = snapshot_id & 0xffff;
282 format!("s{short:04x}:{element_index}")
283}
284
285/// Parse a canonical token string into `(snapshot_id, element_index)`. Returns
286/// `None` on any shape error (unknown prefix, missing colon, non-hex,

Calls

no outgoing calls