Skip to main content

FieldMap

Struct FieldMap 

Source
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: FieldMapContent

Implementations§

Source§

impl FieldMap

Source

pub fn with_capacity(cap: usize) -> Self

Creates a FieldMap with pre-allocated capacity for the given number of fields, avoiding reallocations during parsing.

Source

pub fn init(self) -> Self

Source

pub fn init_with_ordering(&mut self, ordering: TagOrderType)

Source

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.

Source

pub fn has(&self, tag: Tag) -> bool

Returns true if a field with the given tag exists.

Source

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.

Source

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.

Source

pub fn with_bytes<T, F>( &self, tag: Tag, f: F, ) -> Result<T, MessageRejectErrorEnum>
where F: FnOnce(&[u8]) -> Result<T, MessageRejectErrorEnum>,

Borrows the raw bytes for tag and passes them to a closure, avoiding allocation.

Source

pub fn get_bool(&self, tag: Tag) -> Result<bool, MessageRejectErrorEnum>

Returns the field value as a bool (Y = true, N = false).

Source

pub fn get_int(&self, tag: Tag) -> Result<isize, MessageRejectErrorEnum>

Returns the field value parsed as an integer.

Source

pub fn get_time(&self, tag: Tag) -> Result<Timestamp, MessageRejectErrorEnum>

Returns the field value parsed as a UTC timestamp.

Source

pub fn get_string(&self, tag: Tag) -> Result<String, MessageRejectErrorEnum>

Returns the field value as a String.

Source

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.

Source

pub fn set_field<F: FieldValueWriter>( &mut self, tag: Tag, field: F, ) -> &FieldMap

Sets a field by tag and a FieldValueWriter.

Source

pub fn set_bytes(&mut self, tag: Tag, value: &[u8]) -> &FieldMap

Sets a field’s raw bytes directly.

Source

pub fn set_bool(&mut self, tag: Tag, value: bool) -> &FieldMap

Sets a boolean field (true = Y, false = N).

Source

pub fn set_int(&mut self, tag: Tag, value: isize) -> &FieldMap

Sets an integer field.

Source

pub fn set_string(&mut self, tag: Tag, value: &str) -> &FieldMap

Sets a string field.

Source

pub fn remove(&mut self, tag: Tag)

Removes a field by tag. Does nothing if the tag is not present.

Source

pub fn clear(&mut self)

Removes all fields, retaining allocated capacity for reuse.

Source

pub fn copy_into(&self, to: &mut FieldMap)

Deep-copies this FieldMap into to, replacing its contents.

Source

pub fn add(&mut self, f: LocalField)

Source

pub fn set<F: FieldWriter>(&mut self, field: F) -> &FieldMap

Sets a field using a FieldWriter (the tag is derived from the field).

Source

pub fn set_group<F: FieldGroupWriter>(&mut self, field: F) -> &FieldMap

Sets a repeating group field.

Source

pub fn sorted_tags(&mut self) -> Vec<Tag> ⓘ

Source

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
);
Source

pub fn write(&mut self, buffer: &mut Vec<u8>)

Source

pub fn total(&self) -> isize

Source

pub fn length(&self) -> isize

Trait Implementations§

Source§

impl Clone for FieldMap

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldMap

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FieldMap

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more