Skip to main content

Module exact_codec

Module exact_codec 

Source
Expand description

Canonical byte encodings of the exact numbers — the one form they cross a task boundary, the wire and storage in.

Every exact type writes its canonical name: an integer its sign and magnitude, a rational its reduced numerator and denominator, a real algebraic number its minimal polynomial and root index, a hyperreal its reduced numerator and denominator in dt, an infinite natural its residue-indexed polynomials, an ordinal its Cantor normal form, a computable real its exact form or the expression that builds it. Lengths are LEB128 varints.

A decoder trusts nothing it reads. ExactCodec::from_bytes accepts an encoding only when it is complete, has no trailing bytes, and is the canonical encoding of the value it decodes to — so a forged non-canonical name (an unreduced fraction, a reducible “minimal polynomial”, a non-real exponential sum) is refused rather than breaking the equality every other part of the system relies on. Sizes are bounded before any work is done: a minimal polynomial’s degree by MAX_WIRE_DEGREE, collection lengths by MAX_WIRE_LEN, magnitudes by MAX_WIRE_MAGNITUDE bytes, and nesting by MAX_WIRE_DEPTH.

Constants§

MAX_WIRE_DEGREE
The largest minimal-polynomial degree a decoder accepts: an irreducibility check is a factorization, and this bound keeps a hostile encoding from demanding an expensive one.
MAX_WIRE_DEPTH
The deepest nesting a decoded ordinal or expression may have.
MAX_WIRE_LEN
The most elements a decoded collection may claim.
MAX_WIRE_MAGNITUDE
The most magnitude bytes a decoded integer may claim.

Traits§

ExactCodec
A canonical, self-delimiting byte encoding. See the module documentation.

Functions§

read_byte
One byte.
read_len
A length, at most bound.
read_list
write_len
write_list
A length-prefixed list.