pub struct WireWriter { /* private fields */ }Expand description
Build a typed binary blob with magic + version + sections.
Consumers create one writer, push sections in their declared order,
then call into_bytes. Section order is the consumer’s contract;
the envelope itself only enforces the framing.
Implementations§
Source§impl WireWriter
impl WireWriter
Sourcepub fn new(magic: &[u8; 4], version: u32) -> WireWriter
pub fn new(magic: &[u8; 4], version: u32) -> WireWriter
Start a writer with the given magic + version header. The header is emitted immediately so consumers can read offsets predictably.
Sourcepub fn write_section(&mut self, bytes: &[u8]) -> Result<(), EnvelopeError>
pub fn write_section(&mut self, bytes: &[u8]) -> Result<(), EnvelopeError>
Append a length-prefixed byte section. The length is encoded as
a little-endian u32 (bound: 4 GiB per section).
§Errors
Returns EnvelopeError::SectionTooLarge when the byte count cannot
fit in the envelope’s u32 length prefix.
Sourcepub fn write_words(&mut self, words: &[u32]) -> Result<(), EnvelopeError>
pub fn write_words(&mut self, words: &[u32]) -> Result<(), EnvelopeError>
Append a length-prefixed u32 word array. Each word is encoded
little-endian; the prefix counts WORDS, not bytes.
§Errors
Returns EnvelopeError::SectionTooLarge when the word count cannot
fit in the envelope’s u32 length prefix.
Sourcepub fn write_u32(&mut self, value: u32)
pub fn write_u32(&mut self, value: u32)
Append a single little-endian u32. Useful for fixed-width
header fields (state counts, capability flags, etc.) that don’t
need a length prefix.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consume the writer and return the underlying bytes.