Expand description
Bencode — the BitTorrent encoding (BEP-3) as a typed AST.
Bencode is the wire format under every BitTorrent surface: .torrent
metainfo, tracker announces, the DHT’s KRPC, the extension protocol.
This crate is the keystone of the pleme-io ENXAME suite
(theory/ENXAME.md): nothing else parses without it.
It is built in the pleme-io idiom — the TYPED-SPEC + INTERPRETER
TRIPLET (the same shape as mado’s CsiCommand, engawa’s IR,
sui-spec’s domains):
- Typed border —
Bencodeis the parse-don’t-validate AST. Bytes become one of four typed shapes; an ill-formed stream is a typedError, never a panic. - Parser —
parse/parse_prefix: bytes →Bencode. - Emitter —
Bencode::to_bytes: AST → bytes through a typed builder, neverformat!()of the wire syntax (the ★★ TYPED EMISSION rule). Dict keys serialize in sorted order — the canonical contract BitTorrent hashing depends on — guaranteed by thestd::collections::BTreeMapbackingBencode::Dict.
The round-trip law parse(x.to_bytes()) == x and the canonical law
parse(b).map(to_bytes) == b for canonical input are both pinned by
property tests.
Enums§
- Bencode
- A bencoded value — the four shapes the grammar admits.
- Error
- A typed parse failure. Every malformed-stream condition is one of these — the AST is never built from invalid bytes.
Functions§
- parse
- Parse exactly one bencoded value from
input, requiring that the value consumes the entire buffer. - parse_
prefix - Parse one bencoded value from the front of
input, returning the value and the unconsumed tail. Used when bencoded values are framed inside a larger stream (the peer-wire extension handshake, KRPC).