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;

/// `Heartbeat` is the `fix42` `Heartbeat` type, `MsgType` = 0.
pub struct Heartbeat {
    pub message: Message,
}

impl Heartbeat {
    /// Creates a new `Heartbeat` with required fields.
    pub fn new() -> Self {
        let mut msg = Message::new();
        msg.header.set_field(tag::MSG_TYPE, FIXString::from("0".to_string()));

        Self { message: msg }
    }

    /// Creates a `Heartbeat` 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 `TestReqID`, Tag 112.
    pub fn set_test_req_id(&mut self, v: String) {
        self.message.body.set_field(tag::TEST_REQ_ID, FIXString::from(v));
    }

    /// Gets `TestReqID`, Tag 112.
    pub fn get_test_req_id(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::TestReqIDField::new(String::new());
        self.message.body.get_field(tag::TEST_REQ_ID, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `TestReqID` is present, Tag 112.
    pub fn has_test_req_id(&self) -> bool {
        self.message.body.has(tag::TEST_REQ_ID)
    }


}

/// `RouteOut` is the callback type for routing `Heartbeat` messages.
pub type RouteOut = fn(msg: Heartbeat, 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 `Heartbeat`.
pub fn route(router: RouteOut) -> Route {
    let r = move |msg: &Message, session_id: SessionID| -> Result<(), MessageRejectErrorEnum> {
        router(Heartbeat::from_message(msg.clone()), session_id)
    };
    ("FIX.4.2", "0", Box::new(r))
}