refix-codegen 0.8.0

Code generator for typed FIX protocol messages, for the ReFIX engine
Documentation
// @generated by refix codegen from toy.xml. Do not edit.
#![cfg_attr(rustfmt, rustfmt::skip)]

use refix_message::{
    GroupTable, Instances, InvalidValue, KnownTags, LazyKnownTags, Tag, UtcTimestamp,
};

use super::Trailer;

/// The header fields of a message.
#[derive(Clone, Copy)]
pub struct Header<'a>(
    pub(in super::super) refix_message::Scope<'a>,
    pub(in super::super) KnownTags<'static>,
);

impl<'a> From<refix_message::Scope<'a>> for Header<'a> {
    fn from(scope: refix_message::Scope<'a>) -> Self {
        Self(scope, Self::envelope_tags().get())
    }
}

impl<'a> Header<'a> {
    pub(in super::super) const fn envelope_tags() -> &'static LazyKnownTags {
        static TAGS: LazyKnownTags = LazyKnownTags::new(
            &[],
            &[Header::known_tags(), Trailer::known_tags()],
        );
        &TAGS
    }

    pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
        static TAGS: LazyKnownTags = LazyKnownTags::new(
            &[Tag(8), Tag(9), Tag(35), Tag(49), Tag(56), Tag(34), Tag(52), Tag(627)],
            &[HeaderHops::known_tags()],
        );
        &TAGS
    }

    pub fn raw(&self) -> refix_message::Scope<'a> {
        self.0
    }

    /// The `BeginString` (8) field.
    #[doc(alias = "BeginString")]
    pub fn begin_string(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(8))
    }

    /// The `BodyLength` (9) field.
    #[doc(alias = "BodyLength")]
    pub fn body_length(&self) -> Result<Option<i64>, InvalidValue> {
        self.0.get_int(Tag(9))
    }

    /// The `MsgType` (35) field.
    #[doc(alias = "MsgType")]
    pub fn msg_type(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(35))
    }

    /// The `SenderCompID` (49) field.
    #[doc(alias = "SenderCompID")]
    pub fn sender_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(49))
    }

    /// The `TargetCompID` (56) field.
    #[doc(alias = "TargetCompID")]
    pub fn target_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(56))
    }

    /// The `MsgSeqNum` (34) field.
    #[doc(alias = "MsgSeqNum")]
    pub fn msg_seq_num(&self) -> Result<Option<i64>, InvalidValue> {
        self.0.get_int(Tag(34))
    }

    /// The `SendingTime` (52) field.
    #[doc(alias = "SendingTime")]
    pub fn sending_time(&self) -> Result<Option<UtcTimestamp>, InvalidValue> {
        self.0.get_utc_timestamp(Tag(52))
    }

    /// The instances of the `NoHops` (627) group.
    #[doc(alias = "NoHops")]
    pub fn hops(&self) -> Result<Instances<'a, HeaderHops<'a>>, InvalidValue> {
        self.0.get_group(&HeaderHops::TABLE, &self.1).map(Instances::from)
    }
}

impl std::fmt::Debug for Header<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Header({})", self.0.display_known(&Self::known_tags().get()))
    }
}

/// An instance of the `NoHops` (627) group.
#[derive(Clone, Copy)]
pub struct HeaderHops<'a>(refix_message::Scope<'a>);

impl<'a> From<refix_message::Scope<'a>> for HeaderHops<'a> {
    fn from(scope: refix_message::Scope<'a>) -> Self {
        Self(scope)
    }
}

impl<'a> HeaderHops<'a> {
    pub(in super::super) const TABLE: GroupTable<'static> = GroupTable::new(
        Tag(627),
        Tag(628),
        &[Tag(628)],
        &[],
    );

    pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
        static TAGS: LazyKnownTags = LazyKnownTags::new(&[Tag(628)], &[]);
        &TAGS
    }

    pub fn raw(&self) -> refix_message::Scope<'a> {
        self.0
    }

    /// The `HopCompID` (628) field.
    #[doc(alias = "HopCompID")]
    pub fn hop_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(628))
    }
}

impl std::fmt::Debug for HeaderHops<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "HeaderHops({})", self.0)
    }
}