pub struct FieldMap {
pub content: FieldMapContent,
}Expand description
An ordered collection of FIX tag-value fields.
Every FIX Message contains three FieldMaps
exposed as Header,
Body, and
Trailer. Each section uses a different
TagOrderType to control serialization order (header puts 8/9/35 first,
trailer puts CheckSum last, body sorts ascending).
§Reading Fields
Use the typed getters for the common FIX types:
use fixer::field_map::FieldMap;
let mut fm = FieldMap::default().init();
fm.set_string(11, "order-1");
fm.set_int(38, 100);
fm.set_bool(110, true);
assert_eq!(fm.get_string(11).unwrap(), "order-1");
assert_eq!(fm.get_int(38).unwrap(), 100);
assert!(fm.get_bool(110).unwrap());For zero-copy access use get_bytes or
with_bytes.
§Writing Fields
Setters return &FieldMap so calls can be chained when used through the
underlying field_map field:
use fixer::field_map::FieldMap;
let mut fm = FieldMap::default().init();
fm.set_string(11, "order-1");
fm.set_int(38, 100);
assert!(fm.has(11));
assert!(fm.has(38));Fields§
§content: FieldMapContentImplementations§
Source§impl FieldMap
impl FieldMap
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates a FieldMap with pre-allocated capacity for the given number of
fields, avoiding reallocations during parsing.
pub fn init(self) -> Self
pub fn init_with_ordering(&mut self, ordering: TagOrderType)
Sourcepub fn get<P: Field + FieldValueReader>(
&self,
parser: &mut P,
) -> MessageRejectErrorResult
pub fn get<P: Field + FieldValueReader>( &self, parser: &mut P, ) -> MessageRejectErrorResult
Reads a field using its Field implementation (the tag is derived
from parser.tag()). Returns an error if the field is absent or the
value cannot be parsed.
Sourcepub fn get_field<P: FieldValueReader>(
&self,
tag: Tag,
parser: &mut P,
) -> MessageRejectErrorResult
pub fn get_field<P: FieldValueReader>( &self, tag: Tag, parser: &mut P, ) -> MessageRejectErrorResult
Reads the value of the field identified by tag into parser.
Returns an error if the field is absent or the value cannot be parsed.
Sourcepub fn get_bytes(&self, tag: Tag) -> Result<&[u8], MessageRejectErrorEnum>
pub fn get_bytes(&self, tag: Tag) -> Result<&[u8], MessageRejectErrorEnum>
Returns the raw bytes of a field without copying. Returns an error if the tag is absent.
Sourcepub fn with_bytes<T, F>(
&self,
tag: Tag,
f: F,
) -> Result<T, MessageRejectErrorEnum>
pub fn with_bytes<T, F>( &self, tag: Tag, f: F, ) -> Result<T, MessageRejectErrorEnum>
Borrows the raw bytes for tag and passes them to a closure, avoiding
allocation.
Sourcepub fn get_bool(&self, tag: Tag) -> Result<bool, MessageRejectErrorEnum>
pub fn get_bool(&self, tag: Tag) -> Result<bool, MessageRejectErrorEnum>
Returns the field value as a bool (Y = true, N = false).
Sourcepub fn get_int(&self, tag: Tag) -> Result<isize, MessageRejectErrorEnum>
pub fn get_int(&self, tag: Tag) -> Result<isize, MessageRejectErrorEnum>
Returns the field value parsed as an integer.
Sourcepub fn get_time(&self, tag: Tag) -> Result<Timestamp, MessageRejectErrorEnum>
pub fn get_time(&self, tag: Tag) -> Result<Timestamp, MessageRejectErrorEnum>
Returns the field value parsed as a UTC timestamp.
Sourcepub fn get_string(&self, tag: Tag) -> Result<String, MessageRejectErrorEnum>
pub fn get_string(&self, tag: Tag) -> Result<String, MessageRejectErrorEnum>
Returns the field value as a String.
Sourcepub fn get_group<P: FieldGroupReader>(
&self,
parser: P,
) -> Result<P, MessageRejectErrorEnum>
pub fn get_group<P: FieldGroupReader>( &self, parser: P, ) -> Result<P, MessageRejectErrorEnum>
Reads a repeating group. The parser determines the group’s count tag
and member field layout.
Sourcepub fn set_field<F: FieldValueWriter>(
&mut self,
tag: Tag,
field: F,
) -> &FieldMap
pub fn set_field<F: FieldValueWriter>( &mut self, tag: Tag, field: F, ) -> &FieldMap
Sets a field by tag and a FieldValueWriter.
Sourcepub fn set_bytes(&mut self, tag: Tag, value: &[u8]) -> &FieldMap
pub fn set_bytes(&mut self, tag: Tag, value: &[u8]) -> &FieldMap
Sets a field’s raw bytes directly.
Sourcepub fn set_bool(&mut self, tag: Tag, value: bool) -> &FieldMap
pub fn set_bool(&mut self, tag: Tag, value: bool) -> &FieldMap
Sets a boolean field (true = Y, false = N).
Sourcepub fn set_string(&mut self, tag: Tag, value: &str) -> &FieldMap
pub fn set_string(&mut self, tag: Tag, value: &str) -> &FieldMap
Sets a string field.
Sourcepub fn remove(&mut self, tag: Tag)
pub fn remove(&mut self, tag: Tag)
Removes a field by tag. Does nothing if the tag is not present.
Sourcepub fn copy_into(&self, to: &mut FieldMap)
pub fn copy_into(&self, to: &mut FieldMap)
Deep-copies this FieldMap into to, replacing its contents.
pub fn add(&mut self, f: LocalField)
Sourcepub fn set<F: FieldWriter>(&mut self, field: F) -> &FieldMap
pub fn set<F: FieldWriter>(&mut self, field: F) -> &FieldMap
Sets a field using a FieldWriter (the tag is derived from the field).
Sourcepub fn set_group<F: FieldGroupWriter>(&mut self, field: F) -> &FieldMap
pub fn set_group<F: FieldGroupWriter>(&mut self, field: F) -> &FieldMap
Sets a repeating group field.
Sourcepub fn ordered_fields(&mut self) -> Vec<(Tag, &[u8])>
pub fn ordered_fields(&mut self) -> Vec<(Tag, &[u8])>
Returns this map’s fields in wire order, including repeating-group members as a flat sequence.
Works the same whether the message was parsed off the wire or built in
memory, which is the point: parsed_fields
is a parse cache and is dropped on the first mutation, so code that
reads it directly sees nothing for a message the caller constructed.
Use this to walk an arbitrary Message generically — to serialize it
to another encoding, log it, or audit it — without caring how it was
produced.
Takes &mut self because ordering is applied lazily: a built map is
sorted on demand. Nothing observable changes.
use fixer::field_map::FieldMap;
let mut fm = FieldMap::default().init();
fm.set_string(11, "order-1");
fm.set_int(38, 100);
let fields: Vec<_> = fm
.ordered_fields()
.into_iter()
.map(|(tag, value)| (tag, String::from_utf8_lossy(value).into_owned()))
.collect();
assert_eq!(
vec![(11, "order-1".to_string()), (38, "100".to_string())],
fields
);