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;

/// `UserNotification` is the `fix50sp1` `UserNotification` type, `MsgType` = CB.
pub struct UserNotification {
    pub message: Message,
}

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

        msg.body.set_field(tag::USER_STATUS, user_status.0);

        Self { message: msg }
    }

    /// Creates a `UserNotification` 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 `EncodedText`, Tag 355.
    pub fn set_encoded_text(&mut self, v: String) {
        self.message.body.set_field(tag::ENCODED_TEXT, FIXString::from(v));
    }

    /// Gets `EncodedText`, Tag 355.
    pub fn get_encoded_text(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::EncodedTextField::new(String::new());
        self.message.body.get_field(tag::ENCODED_TEXT, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `EncodedText` is present, Tag 355.
    pub fn has_encoded_text(&self) -> bool {
        self.message.body.has(tag::ENCODED_TEXT)
    }




    /// Sets `EncodedTextLen`, Tag 354.
    pub fn set_encoded_text_len(&mut self, v: isize) {
        self.message.body.set_field(tag::ENCODED_TEXT_LEN, fixer::fix_int::FIXInt::from(v));
    }

    /// Gets `EncodedTextLen`, Tag 354.
    pub fn get_encoded_text_len(&self) -> Result<isize, MessageRejectErrorEnum> {
        let mut fld = field::EncodedTextLenField::new(0);
        self.message.body.get_field(tag::ENCODED_TEXT_LEN, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `EncodedTextLen` is present, Tag 354.
    pub fn has_encoded_text_len(&self) -> bool {
        self.message.body.has(tag::ENCODED_TEXT_LEN)
    }




    /// Sets `Text`, Tag 58.
    pub fn set_text(&mut self, v: String) {
        self.message.body.set_field(tag::TEXT, FIXString::from(v));
    }

    /// Gets `Text`, Tag 58.
    pub fn get_text(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::TextField::new(String::new());
        self.message.body.get_field(tag::TEXT, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `Text` is present, Tag 58.
    pub fn has_text(&self) -> bool {
        self.message.body.has(tag::TEXT)
    }




    /// Sets `UserStatus`, Tag 926.
    pub fn set_user_status(&mut self, v: isize) {
        self.message.body.set_field(tag::USER_STATUS, fixer::fix_int::FIXInt::from(v));
    }

    /// Gets `UserStatus`, Tag 926.
    pub fn get_user_status(&self) -> Result<isize, MessageRejectErrorEnum> {
        let mut fld = field::UserStatusField::new(0);
        self.message.body.get_field(tag::USER_STATUS, &mut fld.0)?;
        Ok(fld.value())
    }


    /// Returns true if `UserStatus` is present, Tag 926.
    pub fn has_user_status(&self) -> bool {
        self.message.body.has(tag::USER_STATUS)
    }




    /// Sets `Username`, Tag 553.
    pub fn set_username(&mut self, v: String) {
        self.message.body.set_field(tag::USERNAME, FIXString::from(v));
    }

    /// Gets `Username`, Tag 553.
    pub fn get_username(&self) -> Result<String, MessageRejectErrorEnum> {
        let mut fld = field::UsernameField::new(String::new());
        self.message.body.get_field(tag::USERNAME, &mut fld.0)?;
        Ok(fld.value().to_string())
    }


    /// Returns true if `Username` is present, Tag 553.
    pub fn has_username(&self) -> bool {
        self.message.body.has(tag::USERNAME)
    }


}

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