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>
impl<'a> Message<'a>
Sourcepub fn field(&self, index: usize) -> Field<'a>
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().
Sourcepub fn fields(&self) -> impl Iterator<Item = Field<'a>> + '_
pub fn fields(&self) -> impl Iterator<Item = Field<'a>> + '_
Returns an iterator over all fields, reconstructing each Field<'a>
zero-copy on demand.
Sourcepub fn fix_version(&self) -> Option<&'a [u8]>
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.
Sourcepub fn find(&self, tag: Tag) -> Option<Field<'a>>
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.
Sourcepub fn groups(&self, spec: &GroupSpec) -> GroupIter<'a> ⓘ
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);
}Sourcepub fn validate_body_length(&self) -> Result<(), FixError>
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.
Sourcepub fn validate_checksum(&self) -> Result<(), FixError>
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.