refix-codegen 0.1.0

Typed message code generator for the ReFIX engine
Documentation
// @generated by refix codegen from toy.xml. Do not edit.
#![cfg_attr(rustfmt, rustfmt::skip)]
#![allow(clippy::module_inception)]

use refix_message::{GroupTable, Instances, InvalidValue, KnownTags, MultipleValues, RawMessage, Tag};

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum OrdType<'a> {
    Market,
    Limit,
    Unrecognized(&'a str),
}

impl<'a> OrdType<'a> {
    pub fn from_value(value: &'a str) -> Self {
        match value {
            "1" => Self::Market,
            "2" => Self::Limit,
            unrecognized => Self::Unrecognized(unrecognized),
        }
    }

    pub fn value(self) -> &'a str {
        match self {
            Self::Market => "1",
            Self::Limit => "2",
            Self::Unrecognized(value) => value,
        }
    }
}

impl<'a> From<&'a str> for OrdType<'a> {
    fn from(value: &'a str) -> Self {
        Self::from_value(value)
    }
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ExecInst<'a> {
    NotHeld,
    ParticipateDontInitiate,
    Unrecognized(&'a str),
}

impl<'a> ExecInst<'a> {
    pub fn from_value(value: &'a str) -> Self {
        match value {
            "1" => Self::NotHeld,
            "6" => Self::ParticipateDontInitiate,
            unrecognized => Self::Unrecognized(unrecognized),
        }
    }

    pub fn value(self) -> &'a str {
        match self {
            Self::NotHeld => "1",
            Self::ParticipateDontInitiate => "6",
            Self::Unrecognized(value) => value,
        }
    }
}

impl<'a> From<&'a str> for ExecInst<'a> {
    fn from(value: &'a str) -> Self {
        Self::from_value(value)
    }
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum PartyRole {
    ExecutingFirm,
    ClientId,
    Unrecognized(i64),
}

impl PartyRole {
    pub fn from_value(value: i64) -> Self {
        match value {
            1 => Self::ExecutingFirm,
            3 => Self::ClientId,
            unrecognized => Self::Unrecognized(unrecognized),
        }
    }

    pub fn value(self) -> i64 {
        match self {
            Self::ExecutingFirm => 1,
            Self::ClientId => 3,
            Self::Unrecognized(value) => value,
        }
    }
}

pub mod parties {
    use super::*;

    pub const TABLE: GroupTable<'static> = GroupTable::new(
        Tag(453),
        Tag(448),
        &[Tag(448), Tag(452), Tag(802)],
        &[ptys_sub_grp::TABLE],
    );

    pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[
        Tag(448), Tag(452), Tag(523), Tag(802),
    ]);

    #[derive(Clone, Copy, Debug)]
    pub struct Instance<'a>(refix_message::Scope<'a>);

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

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

        pub fn party_id(&self) -> Result<Option<&'a str>, InvalidValue> {
            self.0.get_str(Tag(448))
        }

        pub fn party_role(&self) -> Result<Option<PartyRole>, InvalidValue> {
            Ok(self.0.get_int(Tag(452))?.map(PartyRole::from_value))
        }

        pub fn ptys_sub_grp(&self) -> Result<Instances<'a, ptys_sub_grp::Instance<'a>>, InvalidValue> {
            self.0.get_group(&ptys_sub_grp::TABLE, &KNOWN_TAGS).map(Instances::from)
        }
    }
}

pub mod ptys_sub_grp {
    use super::*;

    pub const TABLE: GroupTable<'static> = GroupTable::new(Tag(802), Tag(523), &[Tag(523)], &[]);

    pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[Tag(523)]);

    #[derive(Clone, Copy, Debug)]
    pub struct Instance<'a>(refix_message::Scope<'a>);

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

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

        pub fn party_sub_id(&self) -> Result<Option<&'a str>, InvalidValue> {
            self.0.get_str(Tag(523))
        }
    }
}

#[derive(Clone, Copy, Debug)]
pub struct Header<'a>(refix_message::Scope<'a>, KnownTags<'static>);

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

impl<'a> Header<'a> {
    pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[
        Tag(8), Tag(9), Tag(10), Tag(34), Tag(35), Tag(49), Tag(52), Tag(56), Tag(89), Tag(93),
        Tag(627), Tag(628),
    ]);

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

    pub fn begin_string(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(8))
    }

    pub fn body_length(&self) -> Result<Option<i64>, InvalidValue> {
        self.0.get_int(Tag(9))
    }

    pub fn msg_type(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(35))
    }

    pub fn sender_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(49))
    }

    pub fn target_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(56))
    }

    pub fn msg_seq_num(&self) -> Result<Option<i64>, InvalidValue> {
        self.0.get_int(Tag(34))
    }

    pub fn sending_time_raw(&self) -> Option<&'a [u8]> {
        self.0.get(Tag(52))
    }

    pub fn hops(&self) -> Result<Instances<'a, header::hops::Instance<'a>>, InvalidValue> {
        self.0.get_group(&header::hops::TABLE, &self.1).map(Instances::from)
    }
}

pub mod header {
    pub mod hops {
        use super::super::*;

        pub const TABLE: GroupTable<'static> = GroupTable::new(
            Tag(627),
            Tag(628),
            &[Tag(628)],
            &[],
        );

        pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[Tag(628)]);

        #[derive(Clone, Copy, Debug)]
        pub struct Instance<'a>(refix_message::Scope<'a>);

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

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

            pub fn hop_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
                self.0.get_str(Tag(628))
            }
        }
    }
}

#[derive(Clone, Copy, Debug)]
pub struct Trailer<'a>(refix_message::Scope<'a>);

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

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

    pub fn signature_length(&self) -> Result<Option<i64>, InvalidValue> {
        self.0.get_int(Tag(93))
    }

    pub fn signature_raw(&self) -> Option<&'a [u8]> {
        self.0.get(Tag(89))
    }

    pub fn check_sum(&self) -> Result<Option<&'a str>, InvalidValue> {
        self.0.get_str(Tag(10))
    }
}

pub struct NewOrderSingle(RawMessage);

impl NewOrderSingle {
    pub const MSG_TYPE: &[u8] = b"D";

    pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[
        Tag(8), Tag(9), Tag(10), Tag(11), Tag(18), Tag(34), Tag(35), Tag(38), Tag(40), Tag(44),
        Tag(49), Tag(52), Tag(56), Tag(89), Tag(93), Tag(448), Tag(452), Tag(453), Tag(523),
        Tag(627), Tag(628), Tag(802),
    ]);

    pub fn from_raw(raw: RawMessage) -> Self {
        Self(raw)
    }

    pub fn raw(&self) -> &RawMessage {
        &self.0
    }

    pub fn header(&self) -> Header<'_> {
        Header(self.0.scope(), Self::KNOWN_TAGS)
    }

    pub fn trailer(&self) -> Trailer<'_> {
        Trailer(self.0.scope())
    }

    pub fn cl_ord_id(&self) -> Result<Option<&str>, InvalidValue> {
        self.0.get_str(Tag(11))
    }

    pub fn parties(&self) -> Result<Instances<'_, parties::Instance<'_>>, InvalidValue> {
        self.0.get_group(&parties::TABLE, &Self::KNOWN_TAGS).map(Instances::from)
    }

    pub fn order_qty(&self) -> Result<Option<i64>, InvalidValue> {
        self.0.get_int(Tag(38))
    }

    pub fn price_raw(&self) -> Option<&[u8]> {
        self.0.get(Tag(44))
    }

    pub fn ord_type(&self) -> Result<Option<OrdType<'_>>, InvalidValue> {
        Ok(self.0.get_str(Tag(40))?.map(OrdType::from_value))
    }

    pub fn exec_inst(&self) -> Result<Option<MultipleValues<'_, ExecInst<'_>>>, InvalidValue> {
        self.0.get_multiple_values(Tag(18))
    }
}

pub struct Logon(RawMessage);

impl Logon {
    pub const MSG_TYPE: &[u8] = b"A";

    pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[
        Tag(8), Tag(9), Tag(10), Tag(34), Tag(35), Tag(49), Tag(52), Tag(56), Tag(89), Tag(93),
        Tag(372), Tag(384), Tag(627), Tag(628),
    ]);

    pub fn from_raw(raw: RawMessage) -> Self {
        Self(raw)
    }

    pub fn raw(&self) -> &RawMessage {
        &self.0
    }

    pub fn header(&self) -> Header<'_> {
        Header(self.0.scope(), Self::KNOWN_TAGS)
    }

    pub fn trailer(&self) -> Trailer<'_> {
        Trailer(self.0.scope())
    }

    pub fn msg_types(&self) -> Result<Instances<'_, logon::msg_types::Instance<'_>>, InvalidValue> {
        self.0.get_group(&logon::msg_types::TABLE, &Self::KNOWN_TAGS).map(Instances::from)
    }
}

pub mod logon {
    pub mod msg_types {
        use super::super::*;

        pub const TABLE: GroupTable<'static> = GroupTable::new(
            Tag(384),
            Tag(372),
            &[Tag(372)],
            &[],
        );

        pub const KNOWN_TAGS: KnownTags<'static> = KnownTags::new(&[Tag(372)]);

        #[derive(Clone, Copy, Debug)]
        pub struct Instance<'a>(refix_message::Scope<'a>);

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

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

            pub fn ref_msg_type(&self) -> Result<Option<&'a str>, InvalidValue> {
                self.0.get_str(Tag(372))
            }
        }
    }
}