refix-fix42 0.4.0

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

use refix_message::{
    Date, Decimal, GroupTable, Instances, InvalidValue, LazyKnownTags, RawMessage, Tag,
};

use super::super::components::{Header, Trailer};
use super::super::enums::{CommType, NetGrossInd, PriceType, SettlmntTyp, Side};

/// The `BidResponse` (35=l) message.
pub struct BidResponse(RawMessage);

impl BidResponse {
    pub const MSG_TYPE: &[u8] = b"l";

    pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
        static TAGS: LazyKnownTags = LazyKnownTags::new(
            &[Tag(390), Tag(391), Tag(420)],
            &[Header::known_tags(), Trailer::known_tags(), BidResponseBidComponents::known_tags()],
        );
        &TAGS
    }

    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())
    }

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

    /// The `BidID` (390) field.
    #[doc(alias = "BidID")]
    pub fn bid_id(&self) -> Result<Option<&str>, InvalidValue> {
        self.0.get_str(Tag(390))
    }

    /// The `ClientBidID` (391) field.
    #[doc(alias = "ClientBidID")]
    pub fn client_bid_id(&self) -> Result<Option<&str>, InvalidValue> {
        self.0.get_str(Tag(391))
    }

    /// The instances of the `NoBidComponents` (420) group.
    #[doc(alias = "NoBidComponents")]
    pub fn bid_components(&self) -> Result<Instances<'_, BidResponseBidComponents<'_>>, InvalidValue> {
        self.0.get_group(&BidResponseBidComponents::TABLE, &Self::known_tags().get()).map(Instances::from)
    }
}

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

impl std::fmt::Display for BidResponse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(&self.0, f)
    }
}

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

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

impl<'a> BidResponseBidComponents<'a> {
    pub(in super::super) const TABLE: GroupTable<'static> = GroupTable::new(
        Tag(420),
        Tag(12),
        &[
            Tag(12), Tag(13), Tag(44), Tag(54), Tag(58), Tag(63), Tag(64), Tag(66), Tag(336),
            Tag(354), Tag(355), Tag(406), Tag(421), Tag(423), Tag(430),
        ],
        &[],
    );

    pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
        static TAGS: LazyKnownTags = LazyKnownTags::new(
            &[
                Tag(12), Tag(13), Tag(66), Tag(421), Tag(54), Tag(44), Tag(423), Tag(406), Tag(430),
                Tag(63), Tag(64), Tag(336), Tag(58), Tag(354), Tag(355),
            ],
            &[],
        );
        &TAGS
    }

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

    /// The `Commission` (12) field.
    #[doc(alias = "Commission")]
    pub fn commission(&self) -> Result<Option<Decimal>, InvalidValue> {
        self.0.get_decimal(Tag(12))
    }

    /// The `CommType` (13) field.
    #[doc(alias = "CommType")]
    pub fn comm_type(&self) -> Result<Option<CommType<'a>>, InvalidValue> {
        Ok(self.0.get_str(Tag(13))?.map(CommType::from_value))
    }

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

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

    /// The `Side` (54) field.
    #[doc(alias = "Side")]
    pub fn side(&self) -> Result<Option<Side<'a>>, InvalidValue> {
        Ok(self.0.get_str(Tag(54))?.map(Side::from_value))
    }

    /// The `Price` (44) field.
    #[doc(alias = "Price")]
    pub fn price(&self) -> Result<Option<Decimal>, InvalidValue> {
        self.0.get_decimal(Tag(44))
    }

    /// The `PriceType` (423) field.
    #[doc(alias = "PriceType")]
    pub fn price_type(&self) -> Result<Option<PriceType>, InvalidValue> {
        Ok(self.0.get_int(Tag(423))?.map(PriceType::from_value))
    }

    /// The `FairValue` (406) field.
    #[doc(alias = "FairValue")]
    pub fn fair_value(&self) -> Result<Option<Decimal>, InvalidValue> {
        self.0.get_decimal(Tag(406))
    }

    /// The `NetGrossInd` (430) field.
    #[doc(alias = "NetGrossInd")]
    pub fn net_gross_ind(&self) -> Result<Option<NetGrossInd>, InvalidValue> {
        Ok(self.0.get_int(Tag(430))?.map(NetGrossInd::from_value))
    }

    /// The `SettlmntTyp` (63) field.
    #[doc(alias = "SettlmntTyp")]
    pub fn settlmnt_typ(&self) -> Result<Option<SettlmntTyp<'a>>, InvalidValue> {
        Ok(self.0.get_str(Tag(63))?.map(SettlmntTyp::from_value))
    }

    /// The `FutSettDate` (64) field.
    #[doc(alias = "FutSettDate")]
    pub fn fut_sett_date(&self) -> Result<Option<Date>, InvalidValue> {
        self.0.get_date(Tag(64))
    }

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

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

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

    /// The `EncodedText` (355) field.
    #[doc(alias = "EncodedText")]
    pub fn encoded_text(&self) -> Option<&'a [u8]> {
        self.0.get(Tag(355))
    }
}

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