Expand description
Length-prefixed envelope framing for stream transports.
The wire record is:
[ u32 BE length ][ buffa-encoded ObsEnvelope ]No per-record CRC — stream transports (vsock, unix socket, TCP) are reliable byte-streams; buffa decode catches truncation. Any transport that needs integrity beyond TCP-level checksums can wrap the framed stream in its own MAC layer.
Boundary-review § 3.5 (moved upstream from tok-initd::obs::ObsEnvelopeCodec).
§Usage
Reuse a single buffa::SizeCache across every envelope in one
flush window — encode_into_with_cache calls clear() before
each encode so the backing storage is amortised without leaking
stale state between envelopes.
use obs_core::wire::envelope_codec;
use obs_proto::obs::v1::ObsEnvelope;
let env = ObsEnvelope::default();
let mut buf = Vec::with_capacity(4096);
let mut cache = buffa::SizeCache::new();
envelope_codec::encode_into_with_cache(&env, &mut buf, &mut cache);
// On the other side:
if let Some((decoded, consumed)) =
envelope_codec::decode_frame(&buf, 1 << 20).expect("framing ok")
{
assert_eq!(consumed, buf.len());
let _ = decoded;
}Functions§
- decode_
frame - Decode one length-prefixed envelope from
buf. - encode_
into - Encode
envintoout, length-prefixed. Reusesout’s capacity so caller can amortise allocations across envelopes within one flush window. - encode_
into_ with_ cache - Encode
envintooutreusing a caller-ownedSizeCache.