pub struct Decoder { /* private fields */ }Expand description
A reusable FIX message decoder.
Owns a SmallVec buffer that is allocated once (at startup or first use)
and reused across every decode call — zero allocation per message on the
hot path.
Stores (tag, value_start, value_end) byte offsets rather than slices,
eliminating all unsafe lifetime transmutes while preserving zero-allocation
and zero-copy semantics.
§Example
let mut decoder = Decoder::new();
loop {
let msg = decoder.decode(buf)?; // zero allocation after first call
process(msg);
// msg dropped here — decoder buffer ready for next call
}Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new decoder pre-allocated for capacity fields.
Use this when messages consistently exceed 32 fields (e.g. MarketData).
Sourcepub fn decode<'a>(&'a mut self, buf: &'a [u8]) -> Result<Message<'a>, FixError>
pub fn decode<'a>(&'a mut self, buf: &'a [u8]) -> Result<Message<'a>, FixError>
Decode a raw FIX byte buffer into a Message.
Clears and reuses the internal offset buffer — zero allocation per call
after the first. The returned Message<'a> borrows both from self
(the offset slice) and from buf (the raw bytes). Drop Message
before calling decode again.
The sorted tag index used by Message::find is built lazily on the
first find() call and cached for the message lifetime. If find() is
never called, no sort ever happens.
§Errors
FixError::IncompleteMessage— the buffer contains a partial field (no=or no SOH delimiter found); buffer more bytes before retrying.FixError::InvalidTag— a tag contained non-digit bytes or overflowedu32.