Skip to main content

Crate embark_format

Crate embark_format 

Source
Expand description

The on-binary layout shared by every crate in the embark toolkit.

An entry is one embedded file as it appears in the compiled binary: a header naming how the bytes were transformed, followed by the transformed bytes themselves. write_entry produces one at build time and read_header parses one back at runtime; the payload starts at Header::payload_offset.

§Entry layout

bytesmeaning
1tag: CodecId in the low nibble, CryptoId in the high nibble
1..=10original (pre-compression) length, LEB128 varint
12AEAD nonce, present only when the crypto id is not CryptoId::None
16AEAD tag, present under the same condition
restpayload: compressed, then encrypted, in that order

Nothing here compresses or encrypts anything. This crate only decides where the bytes go and what the ids mean, so that embark-codec, embark-crypt, embark-macros and embark all agree on it without depending on each other.

§Features

enc compiles the build-time writing half, dec the runtime reading half. A consumer that only reads embedded files (the common case) needs dec alone. Both imply alloc; std is the default and additionally implies alloc.

Structs§

Header
The decoded header of one on-binary entry, as returned by read_header.

Enums§

CodecId
Names the compression applied to an entry’s payload.
CryptoId
Names the AEAD cipher an entry’s payload was sealed with, if any.
Error
Everything that can go wrong decoding an entry, shared by every crate in the toolkit.

Functions§

read_headerdec
Parses the header at the front of entry.
read_varint
Reads one unsigned LEB128 varint from the front of input, returning the value and how many bytes it occupied.
write_entryenc
Appends one complete entry – header followed by payload – to out.
write_headerenc
Appends the part of the header every entry has – the tag byte and the length varint – to out.
write_varintalloc
Appends value to out as an unsigned LEB128 varint: seven bits of payload per byte, little-endian, with the high bit set on every byte but the last.

Type Aliases§

Result
The toolkit’s Result, defaulting its error type to Error.