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::{Dialect, RawMessage, Tag};

mod components;
mod enums;
mod messages;

#[allow(unused_imports)]
pub use self::{components::*, enums::*, messages::*};

/// The dialect of this dictionary.
pub const DIALECT: Dialect<'static> = Dialect::new().with_extra_length_tags(&[Tag(93)]);

/// A message read as the type its MsgType names.
pub enum Message {
    NewOrderSingle(NewOrderSingle),
    Logon(Logon),
    MassQuote(MassQuote),
    Unrecognized(RawMessage),
}

impl Message {
    pub fn from_raw(raw: RawMessage) -> Self {
        match raw.get(Tag(35)) {
            Some(NewOrderSingle::MSG_TYPE) => Self::NewOrderSingle(NewOrderSingle::from_raw(raw)),
            Some(Logon::MSG_TYPE) => Self::Logon(Logon::from_raw(raw)),
            Some(MassQuote::MSG_TYPE) => Self::MassQuote(MassQuote::from_raw(raw)),
            _ => Self::Unrecognized(raw),
        }
    }
}

impl std::fmt::Debug for Message {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::NewOrderSingle(message) => std::fmt::Debug::fmt(message, f),
            Self::Logon(message) => std::fmt::Debug::fmt(message, f),
            Self::MassQuote(message) => std::fmt::Debug::fmt(message, f),
            Self::Unrecognized(raw) => write!(f, "Unrecognized({raw})"),
        }
    }
}

impl std::fmt::Display for Message {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::NewOrderSingle(message) => std::fmt::Display::fmt(message, f),
            Self::Logon(message) => std::fmt::Display::fmt(message, f),
            Self::MassQuote(message) => std::fmt::Display::fmt(message, f),
            Self::Unrecognized(raw) => std::fmt::Display::fmt(raw, f),
        }
    }
}

/// Builds the tag lists that group reads share.
///
/// Each list is otherwise built by the first read that needs it. Call this
/// once at startup to keep that work out of the first messages.
pub fn warm_up() {
    Header::envelope_tags().get();
    Header::known_tags().get();
    Trailer::known_tags().get();
    Instrument::known_tags().get();
    SecurityXML::known_tags().get();
    OrderQtyData::known_tags().get();
    HeaderHops::known_tags().get();
    Parties::known_tags().get();
    PtysSubGrp::known_tags().get();
    SecAltIDGrp::known_tags().get();
    LogonMsgTypes::known_tags().get();
    MassQuoteQuoteSets::known_tags().get();
    MassQuoteQuoteSetsQuoteEntries::known_tags().get();
    NewOrderSingle::known_tags().get();
    Logon::known_tags().get();
    MassQuote::known_tags().get();
}