Skip to main content

Message

Struct Message 

Source
pub struct Message<'a> { /* private fields */ }
Expand description

A decoded FIX message.

Zero-copy: field values are sub-slices of the original input buffer — no bytes are copied when accessing fields.

The sorted tag index for [find] is built lazily on the first call and cached for the lifetime of the message. This means decode() pays no sort cost when you never call find(), and pays it at most once when you do.

Implementations§

Source§

impl<'a> Message<'a>

Source

pub fn len(&self) -> usize

Number of fields in the message.

Source

pub fn is_empty(&self) -> bool

Returns true if the message contains no fields.

Source

pub fn field(&self, index: usize) -> Field<'a>

Returns the field at index, reconstructing it zero-copy from the stored byte offsets. Panics if index >= self.len().

Source

pub fn fields(&self) -> impl Iterator<Item = Field<'a>> + '_

Returns an iterator over all fields, reconstructing each Field<'a> zero-copy on demand.

Source

pub fn fix_version(&self) -> Option<&'a [u8]>

Return the value of tag 8 (BEGIN_STRING) as a byte slice, or None if the field is absent.

Common values are b"FIX.4.2", b"FIX.4.4", b"FIXT.1.1", etc.

Source

pub fn find(&self, tag: Tag) -> Option<Field<'a>>

Find the first field with the given tag, or None if not present.

The sorted index is built lazily on the first call (O(n log n)) and cached for subsequent calls (O(log n) binary search). If find() is never called, the sort never happens.

Source

pub fn groups(&self, spec: &GroupSpec) -> GroupIter<'a>

Return an iterator over the instances of the repeating group described by spec.

The iterator is zero-copy: each Group borrows directly into this message’s offset slice and raw buffer. If the count tag is absent or its value is 0, the iterator yields nothing.

§Example
for entry in msg.groups(&group::MD_ENTRIES) {
    let ty  = entry.find(tag::MD_ENTRY_TYPE);
    let px  = entry.find(tag::MD_ENTRY_PX);
}
Source

pub fn validate_body_length(&self) -> Result<(), FixError>

Return an iterator over every repeating group present in this message.

Scans the appropriate group spec array based on the FIX version detected from tag 8 (BEGIN_STRING): FIX42_GROUPS for FIX 4.2 messages, and both FIX42_GROUPS + FIX44_GROUPS for FIX 4.4 messages (which is a superset). Yields (&'static GroupSpec, GroupIter<'a>) for each spec whose count tag is found in the message with a non-zero count. Groups whose count tag is absent or zero are skipped.

The order follows the order of the spec arrays, not the order fields appear in the message.

§Example
for (spec, instances) in msg.all_groups() {
    for g in instances {
        // process each group instance
    }
}

Validate the BodyLength field (tag 9).

A FIX message body spans from the first byte after the 9=…\x01 field up to and including the SOH that terminates the last field before 10=. This method computes that byte count from the raw buffer and compares it to the value declared in tag 9.

§Errors

Returns FixError::InvalidBodyLength when:

  • The message has fewer than 3 fields (no room for tags 8, 9, and 10).
  • Tag 9 is not at position 1 or its value cannot be parsed as an integer.
  • Tag 10 is not the last field.
  • The computed byte count does not match the declared value.
Source

pub fn validate_checksum(&self) -> Result<(), FixError>

Validate the CheckSum field (tag 10).

The FIX checksum is the sum of every byte from the start of the buffer up to (but not including) the 10= tag bytes, taken mod 256. This method computes that value and compares it to the 3-digit decimal string stored in tag 10.

§Errors

Returns FixError::InvalidCheckSum when:

  • The message has fewer than 1 field.
  • Tag 10 is not the last field or its value cannot be parsed.
  • The computed checksum does not match the declared value.
Source

pub fn all_groups( &self, ) -> impl Iterator<Item = (&'static GroupSpec, GroupIter<'a>)> + '_

Trait Implementations§

Source§

impl<'a> Debug for Message<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Message<'a>

§

impl<'a> !RefUnwindSafe for Message<'a>

§

impl<'a> Send for Message<'a>

§

impl<'a> !Sync for Message<'a>

§

impl<'a> Unpin for Message<'a>

§

impl<'a> UnsafeUnpin for Message<'a>

§

impl<'a> UnwindSafe for Message<'a>

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.