Skip to main content

Decoder

Struct Decoder 

Source
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

Source

pub fn new() -> Self

Create a new decoder with a default inline capacity of 32 fields.

Source

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).

Source

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 overflowed u32.

Trait Implementations§

Source§

impl Default for Decoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.