#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{
GroupTable, Instances, InvalidValue, KnownTags, LazyKnownTags, Tag, UtcTimestamp,
};
use super::Trailer;
#[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
}
#[doc(alias = "BeginString")]
pub fn begin_string(&self) -> Result<Option<&'a str>, InvalidValue> {
self.0.get_str(Tag(8))
}
#[doc(alias = "BodyLength")]
pub fn body_length(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(9))
}
#[doc(alias = "MsgType")]
pub fn msg_type(&self) -> Result<Option<&'a str>, InvalidValue> {
self.0.get_str(Tag(35))
}
#[doc(alias = "SenderCompID")]
pub fn sender_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
self.0.get_str(Tag(49))
}
#[doc(alias = "TargetCompID")]
pub fn target_comp_id(&self) -> Result<Option<&'a str>, InvalidValue> {
self.0.get_str(Tag(56))
}
#[doc(alias = "MsgSeqNum")]
pub fn msg_seq_num(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(34))
}
#[doc(alias = "SendingTime")]
pub fn sending_time(&self) -> Result<Option<UtcTimestamp>, InvalidValue> {
self.0.get_utc_timestamp(Tag(52))
}
#[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()))
}
}
#[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
}
#[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)
}
}