Expand description
Zero-dependency recursive decoder for encoded and binary data.
bytepeel-core takes opaque input (a hex dump, a base64 blob, a PEM block,
raw bytes) and peels it layer by layer into a Node tree. Where the bytes
are genuinely ambiguous (a protobuf length-delimited field could be a string,
a submessage or packed varints) it keeps the top interpretations with scores
instead of silently picking one.
use bytepeel_core::{peel, Options, Detail};
let node = peel(b"SGVsbG8gd29ybGQ=", &Options::default()).unwrap();
assert_eq!(node.codec.name(), "base64");
let Detail::Layer { child, .. } = &node.detail else { panic!() };
assert!(matches!(&child.detail, Detail::Text { text, .. } if text == "Hello world"));Modules§
- varint
- LEB128 varints as used by protobuf.
Structs§
- Alt
- Asn1
- One DER element (tag, length, value).
- B64
- Result of decoding base64 text.
- Diag
- A machine-readable diagnostic: used both for hard errors and node warnings.
- Field
- Json
Pick - A value inside JSON text.
- JwtPick
- A JWT part picked by
select_jwt, optionally narrowed to one JSON value inside the header or payload. - Node
- Options
- Decoding options.
- Value
- One decoded value: a byte range and its kind.
Enums§
- Alphabet
- AltKind
- Asn1
Value - Codec
- Detail
- Field
Value - Force
- Force the interpretation of the first non-text-encoding layer.
- Input
Form - How to read the top-level input.
- NewValue
- A new value for a field, parsed from the CLI syntax (see
parse_value). - Op
- One edit for
edit. Paths are the--getpaths of the decoded tree. - Pick
- What a path selected.
- TagClass
- ASN.1 tag class.
- Value
Kind
Constants§
- BYTES_
HEAD - Bytes kept in a
Detail::Bytesleaf for its preview. - MAX_
ITEMS - Default for
Options::max_items. - TEXT_
HEAD - Characters kept in a
Detail::Textleaf.
Functions§
- asn1_
to_ json - Serialize a single DER element (e.g. the result of
select_der) as JSON. - asn1_
to_ tree - Render a single DER element as an indented outline.
- decode_
b64 - Decode base64 text: standard (
+/) or URL-safe (-_) alphabet, padded or unpadded, with line breaks allowed (PEM-style wrapping). Other whitespace inside the data is rejected. - decode_
hex - Strictly decode hex text. Whitespace and
:separate tokens; each token may carry a0xprefix and must have an even number of digits. - diag_
to_ json - Serialize a diagnostic as
{"error":{"code":..,"message":..,"offset":..}}. - edit
- Apply one edit and re-encode every enclosing layer in its original style. The output is decoded again with the same options and checked; the result is returned only if it holds exactly the requested change.
- field_
to_ json - Serialize a single protobuf field (e.g. the result of
select) as JSON. - field_
to_ tree - Render a single protobuf field as an indented outline.
- get
- Select by a path that may cross formats, e.g.
2.0.0.5for the subject of a base64 certificate in protobuf string field 2, ortoken.payload.subfor a JWT in a CBOR byte string. - innermost
- The bytes the innermost item was decoded from: the decoded bytes of the
last text or compression layer (hex, base64, PEM, dump, gzip, zlib, zstd),
or
inputitself whenrootis not a layer.rootmust bepeel(input, ..)’s result. This is the whole payload, never a preview: base64 → gzip → text gives the full text. - is_der
- True when
node(after any text layers) is DER, so paths are element indices. A PEM bundle counts when every block is DER. - is_jwt
- True when
node(after any text layers) is a JWT. - is_
values - True when
node(after any text layers) is CBOR or MessagePack. - parse_
value - Parse a value in the CLI syntax.
- peel
- Decode
inputinto a tree of layers. - select
- Select a protobuf field by path.
- select_
der - Select a DER element by path.
- select_
jwt - Select a JWT part by name (
payload) or index (1), then optionally a value inside its JSON (payload.sub,header.alg,payload.roles.0). JSON segments are object keys (matched exactly; the first of duplicate keys wins) or array indices. Keys containing.cannot be addressed. - select_
value - Select a CBOR or MessagePack value by path.
- set
- Set the field at
pathtovalue:edit(input, opts, &Op::Set(..)). - to_json
- Serialize a node tree as compact JSON. See
docs/DESIGN.mdfor the schema. - to_tree
- Render a node tree as an indented, human-readable outline.
- value_
to_ json - Serialize a single CBOR value (e.g. the result of
select_value) as JSON. - value_
to_ tree - Render a single CBOR value as an indented outline.