#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{GroupTable, Instances, InvalidValue, LazyKnownTags, RawMessage, Tag};
use super::super::components::{Header, Trailer};
use super::super::enums::{EncryptMethod, MsgDirection};
pub struct Logon(RawMessage);
impl Logon {
pub const MSG_TYPE: &[u8] = b"A";
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[
Tag(98), Tag(108), Tag(95), Tag(96), Tag(141), Tag(789), Tag(383), Tag(384),
Tag(464), Tag(553), Tag(554),
],
&[Header::known_tags(), Trailer::known_tags(), LogonMsgTypes::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 = "EncryptMethod")]
pub fn encrypt_method(&self) -> Result<Option<EncryptMethod>, InvalidValue> {
Ok(self.0.get_int(Tag(98))?.map(EncryptMethod::from_value))
}
#[doc(alias = "HeartBtInt")]
pub fn heart_bt_int(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(108))
}
#[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))
}
#[doc(alias = "ResetSeqNumFlag")]
pub fn reset_seq_num_flag(&self) -> Result<Option<bool>, InvalidValue> {
self.0.get_bool(Tag(141))
}
#[doc(alias = "NextExpectedMsgSeqNum")]
pub fn next_expected_msg_seq_num(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(789))
}
#[doc(alias = "MaxMessageSize")]
pub fn max_message_size(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(383))
}
#[doc(alias = "NoMsgTypes")]
pub fn msg_types(&self) -> Result<Instances<'_, LogonMsgTypes<'_>>, InvalidValue> {
self.0.get_group(&LogonMsgTypes::TABLE, &Self::known_tags().get()).map(Instances::from)
}
#[doc(alias = "TestMessageIndicator")]
pub fn test_message_indicator(&self) -> Result<Option<bool>, InvalidValue> {
self.0.get_bool(Tag(464))
}
#[doc(alias = "Username")]
pub fn username(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(553))
}
#[doc(alias = "Password")]
pub fn password(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(554))
}
}
impl std::fmt::Debug for Logon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Logon({})", self.0)
}
}
impl std::fmt::Display for Logon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}
#[derive(Clone, Copy)]
pub struct LogonMsgTypes<'a>(refix_message::Scope<'a>);
impl<'a> From<refix_message::Scope<'a>> for LogonMsgTypes<'a> {
fn from(scope: refix_message::Scope<'a>) -> Self {
Self(scope)
}
}
impl<'a> LogonMsgTypes<'a> {
pub(in super::super) const TABLE: GroupTable<'static> = GroupTable::new(
Tag(384),
Tag(372),
&[Tag(372), Tag(385)],
&[],
);
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(&[Tag(372), Tag(385)], &[]);
&TAGS
}
pub fn raw(&self) -> refix_message::Scope<'a> {
self.0
}
#[doc(alias = "RefMsgType")]
pub fn ref_msg_type(&self) -> Result<Option<&'a str>, InvalidValue> {
self.0.get_str(Tag(372))
}
#[doc(alias = "MsgDirection")]
pub fn msg_direction(&self) -> Result<Option<MsgDirection<'a>>, InvalidValue> {
Ok(self.0.get_str(Tag(385))?.map(MsgDirection::from_value))
}
}
impl std::fmt::Debug for LogonMsgTypes<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "LogonMsgTypes({})", self.0)
}
}