#![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::Urgency;
pub struct News(RawMessage);
impl News {
pub const MSG_TYPE: &[u8] = b"B";
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[
Tag(42), Tag(61), Tag(148), Tag(358), Tag(359), Tag(215), Tag(146), Tag(555),
Tag(711), Tag(33), Tag(149), Tag(95), Tag(96),
],
&[
Header::known_tags(), Trailer::known_tags(), RoutingGrp::known_tags(),
InstrmtGrp::known_tags(), InstrmtLegGrp::known_tags(), UndInstrmtGrp::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 = "OrigTime")]
pub fn orig_time(&self) -> Result<Option<UtcTimestamp>, InvalidValue> {
self.0.get_utc_timestamp(Tag(42))
}
#[doc(alias = "Urgency")]
pub fn urgency(&self) -> Result<Option<Urgency<'_>>, InvalidValue> {
Ok(self.0.get_str(Tag(61))?.map(Urgency::from_value))
}
#[doc(alias = "Headline")]
pub fn headline(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(148))
}
#[doc(alias = "EncodedHeadlineLen")]
pub fn encoded_headline_len(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(358))
}
#[doc(alias = "EncodedHeadline")]
pub fn encoded_headline(&self) -> Option<&[u8]> {
self.0.get(Tag(359))
}
#[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 = "NoLegs")]
pub fn legs(&self) -> Result<Instances<'_, InstrmtLegGrp<'_>>, InvalidValue> {
self.0.get_group(&InstrmtLegGrp::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 = "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 = "URLLink")]
pub fn url_link(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(149))
}
#[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 News {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "News({})", self.0)
}
}
impl std::fmt::Display for News {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}