pub struct StorageEnvelope {
pub compressed_data: Vec<u8>,
pub checksum: [u8; 8],
pub original_size: u32,
pub format: String,
}Expand description
Storage envelope for raw byte storage Contains compressed data with integrity checking
Fields§
§compressed_data: Vec<u8>Compressed payload data
Serialized as msgpack bin (protocol 1.1, envelope-bin-encoding.md).
Scope is strictly this field: checksum stays array-of-ints by
normative exclusion (crypto-adjacent surface — MUST NOT flip).
checksum: [u8; 8]xxHash3-64 checksum for integrity (8 bytes)
original_size: u32Original size for validation
format: StringFormat identifier (e.g., “msgpack”)
Implementations§
Source§impl StorageEnvelope
impl StorageEnvelope
Sourcepub fn new(data: &[u8], format: String) -> Result<Self, ByteStorageError>
pub fn new(data: &[u8], format: String) -> Result<Self, ByteStorageError>
Create new envelope with data compression and checksum.
Takes the input by shared slice: it is only compressed and hashed (both
borrow), never retained, so there is no reason to own it. Avoids a
full-payload copy (up to MAX_UNCOMPRESSED_SIZE) on the write path.
Sourcepub fn extract(&self) -> Result<Vec<u8>, ByteStorageError>
pub fn extract(&self) -> Result<Vec<u8>, ByteStorageError>
Extract and validate data from envelope
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Exact length of this envelope’s MessagePack encoding: the bytes
encode_into writes and ByteStorage::store
returns.
Computed from the field lengths and values without encoding anything, so a caller can allocate the output once, at its final size.
Sourcepub fn encode_into(&self, out: &mut [u8]) -> Result<(), ByteStorageError>
pub fn encode_into(&self, out: &mut [u8]) -> Result<(), ByteStorageError>
Write this envelope’s MessagePack encoding, the bytes
ByteStorage::store returns, into out, which must be exactly
encoded_len bytes long.
For a binding that owns the output memory (a Python bytes, say): it
sizes the buffer with encoded_len and writes once, with no
intermediate Vec and no MessagePack dependency of its own. Measure
before using it for envelopes of 64 KiB and up: removing a
payload-sized buffer there can make an operation slower under glibc’s
malloc (see ByteStorage::store, which therefore does not).
§Errors
InputTooLarge when the encoding exceeds the envelope size cap, the
same final check store makes. SerializationFailed when out is not
encoded_len bytes; nothing written into it is then meaningful.