Skip to main content

fixer_fix/fix40/
logon.rs

1// Code generated by fixer-gen. DO NOT EDIT.
2#![allow(clippy::new_without_default)]
3#![allow(clippy::needless_pass_by_value)]
4#![allow(clippy::too_many_arguments)]
5#![allow(unused_imports)]
6
7use fixer::message::Message;
8use fixer::fix_string::FIXString;
9use fixer::errors::MessageRejectErrorEnum;
10use fixer::session::session_id::SessionID;
11
12
13use crate::field;
14use crate::tag;
15
16/// `Logon` is the `fix40` `Logon` type, `MsgType` = A.
17pub struct Logon {
18    pub message: Message,
19}
20
21impl Logon {
22    /// Creates a new `Logon` with required fields.
23    pub fn new(encrypt_method: field::EncryptMethodField, heart_bt_int: field::HeartBtIntField) -> Self {
24        let mut msg = Message::new();
25        msg.header.set_field(tag::MSG_TYPE, FIXString::from("A".to_string()));
26
27        msg.body.set_field(tag::ENCRYPT_METHOD, encrypt_method.0);
28
29        msg.body.set_field(tag::HEART_BT_INT, heart_bt_int.0);
30
31        Self { message: msg }
32    }
33
34    /// Creates a `Logon` from an existing `Message`.
35    pub fn from_message(msg: Message) -> Self {
36        Self { message: msg }
37    }
38
39    /// Returns the underlying `Message`.
40    pub fn to_message(self) -> Message {
41        self.message
42    }
43
44
45
46
47    /// Sets `EncryptMethod`, Tag 98.
48    pub fn set_encrypt_method(&mut self, v: isize) {
49        self.message.body.set_field(tag::ENCRYPT_METHOD, fixer::fix_int::FIXInt::from(v));
50    }
51
52    /// Gets `EncryptMethod`, Tag 98.
53    pub fn get_encrypt_method(&self) -> Result<isize, MessageRejectErrorEnum> {
54        let mut fld = field::EncryptMethodField::new(0);
55        self.message.body.get_field(tag::ENCRYPT_METHOD, &mut fld.0)?;
56        Ok(fld.value())
57    }
58
59
60    /// Returns true if `EncryptMethod` is present, Tag 98.
61    pub fn has_encrypt_method(&self) -> bool {
62        self.message.body.has(tag::ENCRYPT_METHOD)
63    }
64
65
66
67
68    /// Sets `HeartBtInt`, Tag 108.
69    pub fn set_heart_bt_int(&mut self, v: isize) {
70        self.message.body.set_field(tag::HEART_BT_INT, fixer::fix_int::FIXInt::from(v));
71    }
72
73    /// Gets `HeartBtInt`, Tag 108.
74    pub fn get_heart_bt_int(&self) -> Result<isize, MessageRejectErrorEnum> {
75        let mut fld = field::HeartBtIntField::new(0);
76        self.message.body.get_field(tag::HEART_BT_INT, &mut fld.0)?;
77        Ok(fld.value())
78    }
79
80
81    /// Returns true if `HeartBtInt` is present, Tag 108.
82    pub fn has_heart_bt_int(&self) -> bool {
83        self.message.body.has(tag::HEART_BT_INT)
84    }
85
86
87
88
89    /// Sets `RawData`, Tag 96.
90    pub fn set_raw_data(&mut self, v: String) {
91        self.message.body.set_field(tag::RAW_DATA, FIXString::from(v));
92    }
93
94    /// Gets `RawData`, Tag 96.
95    pub fn get_raw_data(&self) -> Result<String, MessageRejectErrorEnum> {
96        let mut fld = field::RawDataField::new(String::new());
97        self.message.body.get_field(tag::RAW_DATA, &mut fld.0)?;
98        Ok(fld.value().to_string())
99    }
100
101
102    /// Returns true if `RawData` is present, Tag 96.
103    pub fn has_raw_data(&self) -> bool {
104        self.message.body.has(tag::RAW_DATA)
105    }
106
107
108
109
110    /// Sets `RawDataLength`, Tag 95.
111    pub fn set_raw_data_length(&mut self, v: isize) {
112        self.message.body.set_field(tag::RAW_DATA_LENGTH, fixer::fix_int::FIXInt::from(v));
113    }
114
115    /// Gets `RawDataLength`, Tag 95.
116    pub fn get_raw_data_length(&self) -> Result<isize, MessageRejectErrorEnum> {
117        let mut fld = field::RawDataLengthField::new(0);
118        self.message.body.get_field(tag::RAW_DATA_LENGTH, &mut fld.0)?;
119        Ok(fld.value())
120    }
121
122
123    /// Returns true if `RawDataLength` is present, Tag 95.
124    pub fn has_raw_data_length(&self) -> bool {
125        self.message.body.has(tag::RAW_DATA_LENGTH)
126    }
127
128
129}
130
131/// `RouteOut` is the callback type for routing `Logon` messages.
132pub type RouteOut = fn(msg: Logon, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;
133
134/// Route type returned by the `route` function.
135pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);
136
137/// Returns the begin string, message type, and route function for `Logon`.
138pub fn route(router: RouteOut) -> Route {
139    let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
140        router(Logon::from_message(msg.clone()), session_id)
141    };
142    ("FIX.4.0", "A", Box::new(r))
143}