#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{Instances, InvalidValue, LazyKnownTags, RawMessage, Tag, UtcTimestamp};
use super::super::components::{
Header, InstrmtGrp, InstrmtLegGrp, LinesOfTextGrp, RoutingGrp, Trailer, UndInstrmtGrp,
};
use super::super::enums::EmailType;
pub struct Email(RawMessage);
impl Email {
pub const MSG_TYPE: &[u8] = b"C";
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[
Tag(164), Tag(94), Tag(42), Tag(147), Tag(356), Tag(357), Tag(215), Tag(146),
Tag(711), Tag(555), Tag(37), Tag(11), Tag(33), Tag(95), Tag(96),
],
&[
Header::known_tags(), Trailer::known_tags(), RoutingGrp::known_tags(),
InstrmtGrp::known_tags(), UndInstrmtGrp::known_tags(), InstrmtLegGrp::known_tags(),
LinesOfTextGrp::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(), Self::known_tags().get())
}
pub fn trailer(&self) -> Trailer<'_> {
Trailer(self.0.scope())
}
#[doc(alias = "EmailThreadID")]
pub fn email_thread_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(164))
}
#[doc(alias = "EmailType")]
pub fn email_type(&self) -> Result<Option<EmailType<'_>>, InvalidValue> {
Ok(self.0.get_str(Tag(94))?.map(EmailType::from_value))
}
#[doc(alias = "OrigTime")]
pub fn orig_time(&self) -> Result<Option<UtcTimestamp>, InvalidValue> {
self.0.get_utc_timestamp(Tag(42))
}
#[doc(alias = "Subject")]
pub fn subject(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(147))
}
#[doc(alias = "EncodedSubjectLen")]
pub fn encoded_subject_len(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(356))
}
#[doc(alias = "EncodedSubject")]
pub fn encoded_subject(&self) -> Option<&[u8]> {
self.0.get(Tag(357))
}
#[doc(alias = "NoRoutingIDs")]
pub fn routing_ids(&self) -> Result<Instances<'_, RoutingGrp<'_>>, InvalidValue> {
self.0.get_group(&RoutingGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "NoRelatedSym")]
pub fn related_sym(&self) -> Result<Instances<'_, InstrmtGrp<'_>>, InvalidValue> {
self.0.get_group(&InstrmtGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "NoUnderlyings")]
pub fn underlyings(&self) -> Result<Instances<'_, UndInstrmtGrp<'_>>, InvalidValue> {
self.0.get_group(&UndInstrmtGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "NoLegs")]
pub fn legs(&self) -> Result<Instances<'_, InstrmtLegGrp<'_>>, InvalidValue> {
self.0.get_group(&InstrmtLegGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "OrderID")]
pub fn order_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(37))
}
#[doc(alias = "ClOrdID")]
pub fn cl_ord_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(11))
}
#[doc(alias = "NoLinesOfText")]
pub fn lines_of_text(&self) -> Result<Instances<'_, LinesOfTextGrp<'_>>, InvalidValue> {
self.0.get_group(&LinesOfTextGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "RawDataLength")]
pub fn raw_data_length(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(95))
}
#[doc(alias = "RawData")]
pub fn raw_data(&self) -> Option<&[u8]> {
self.0.get(Tag(96))
}
}
impl std::fmt::Debug for Email {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Email({})", self.0)
}
}
impl std::fmt::Display for Email {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}