Skip to main content

Module wirelen

Module wirelen 

Source
Expand description

WireLen<T> — a length/count field that auto-derives by default but can be pinned.

A wire length or count (a UDP length, a DNS qdcount, an rdlength) normally equals the real size of what it describes, but a dual-use codec must also let you write a value that disagrees (a forged/malformed frame). WireLen<T> is that field: it is either

  • Auto — “derive me at encode” (the Default), or
  • Set — “write exactly this value” (an override, or a decoded value).

On decode it always yields Set(decoded), so decode → encode stays byte-identical (a forged length survives a round-trip). On encode, an Auto is resolved from a declared target via the #[bw(auto_len = count(x) | bytes(x))] field directive (same-struct target) or the #[bin(auto_len(path = count(field), …))] struct directive (cross-struct); a Set is written as-is. So plain to_bytes() is correct by default, yet WireLen::set(n) deliberately deviates. Derivation is checked (CountPrefix) — an oversized length is a BitError, never a silent truncation.

Enums§

WireLen
A wire length/count field: Auto-derived by default, or an explicit Set override. See the module docs.