fixer-fix 0.10.1

Generated FIX protocol types for fixer
Documentation
// Code generated by fixer-gen. DO NOT EDIT.
#![allow(clippy::new_without_default)]
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::too_many_arguments)]
#![allow(unused_imports)]

use fixer::message::Message;
use fixer::fix_string::FIXString;
use fixer::errors::MessageRejectErrorEnum;
use fixer::session::session_id::SessionID;


use crate::field;
use crate::tag;

/// `Logon` is the `fix40` `Logon` type, `MsgType` = A.
pub struct Logon {
    pub message: Message,
}

impl Logon {
    /// Creates a new `Logon` with required fields.
    pub fn new(encrypt_method: field::EncryptMethodField, heart_bt_int: field::HeartBtIntField) -> Self {
        let mut msg = Message::new();
        msg.header.set_field(tag::MSG_TYPE, FIXString::from("A".to_string()));

        msg.body.set_field(tag::ENCRYPT_METHOD, encrypt_method.0);

        msg.body.set_field(tag::HEART_BT_INT, heart_bt_int.0);

        Self { message: msg }
    }

    /// Creates a `Logon` from an existing `Message`.
    pub fn from_message(msg: Message) -> Self {
        Self { message: msg }
    }

    /// Returns the underlying `Message`.
    pub fn to_message(self) -> Message {
        self.message
    }




    /// Sets `EncryptMethod`, Tag 98.
    pub fn set_encrypt_method(&mut self, v: isize) {
        self.message.body.set_field(tag::ENCRYPT_METHOD, fixer::fix_int::FIXInt::from(v));
    }

    /// Gets `EncryptMethod`, Tag 98.
    pub fn get_encrypt_method(&self) -> Result<isize, MessageRejectErrorEnum> {
        let mut fld = field::EncryptMethodField::new(0);
        self.message.body.get_field(tag::ENCRYPT_METHOD, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `EncryptMethod` is present, Tag 98.
    pub fn has_encrypt_method(&self) -> bool {
        self.message.body.has(tag::ENCRYPT_METHOD)
    }




    /// Sets `HeartBtInt`, Tag 108.
    pub fn set_heart_bt_int(&mut self, v: isize) {
        self.message.body.set_field(tag::HEART_BT_INT, fixer::fix_int::FIXInt::from(v));
    }

    /// Gets `HeartBtInt`, Tag 108.
    pub fn get_heart_bt_int(&self) -> Result<isize, MessageRejectErrorEnum> {
        let mut fld = field::HeartBtIntField::new(0);
        self.message.body.get_field(tag::HEART_BT_INT, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `HeartBtInt` is present, Tag 108.
    pub fn has_heart_bt_int(&self) -> bool {
        self.message.body.has(tag::HEART_BT_INT)
    }




    /// Sets `RawData`, Tag 96.
    pub fn set_raw_data(&mut self, v: String) {
        self.message.body.set_field(tag::RAW_DATA, FIXString::from(v));
    }

    /// Gets `RawData`, Tag 96.
    pub fn get_raw_data(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::RawDataField::new(String::new());
        self.message.body.get_field(tag::RAW_DATA, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `RawData` is present, Tag 96.
    pub fn has_raw_data(&self) -> bool {
        self.message.body.has(tag::RAW_DATA)
    }




    /// Sets `RawDataLength`, Tag 95.
    pub fn set_raw_data_length(&mut self, v: isize) {
        self.message.body.set_field(tag::RAW_DATA_LENGTH, fixer::fix_int::FIXInt::from(v));
    }

    /// Gets `RawDataLength`, Tag 95.
    pub fn get_raw_data_length(&self) -> Result<isize, MessageRejectErrorEnum> {
        let mut fld = field::RawDataLengthField::new(0);
        self.message.body.get_field(tag::RAW_DATA_LENGTH, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `RawDataLength` is present, Tag 95.
    pub fn has_raw_data_length(&self) -> bool {
        self.message.body.has(tag::RAW_DATA_LENGTH)
    }


}

/// `RouteOut` is the callback type for routing `Logon` messages.
pub type RouteOut = fn(msg: Logon, session_id: SessionID) -> Result<(), MessageRejectErrorEnum>;

/// Route type returned by the `route` function.
pub type Route = (&'static str, &'static str, Box<dyn Fn(&Message, SessionID) -> Result<(), MessageRejectErrorEnum> + Send>);

/// Returns the begin string, message type, and route function for `Logon`.
pub fn route(router: RouteOut) -> Route {
    let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
        router(Logon::from_message(msg.clone()), session_id)
    };
    ("FIX.4.0", "A", Box::new(r))
}