Trait fbp::fbp_iidmessage::MessageSerializer [−][src]
pub trait MessageSerializer { fn make_self_from_string<'a, T>(json_string: &'a str) -> T
where
T: Sized + Deserialize<'a>, { ... } fn make_message(&self, msg_type: MessageType) -> IIDMessage
where
Self: Sized + Serialize, { ... } }
Expand description
The MessageSerializer trait is used to serialize and deserialize structs so that they may become the payload of an IIDMessage
Example
use fbp::fbp_iidmessage::*; // config_data is a JSON string to set a path to a log file let config_data = "{\"log_file_path\":\"Log_file.txt\"}".to_string(); // This creates the new ConfigMessage with the config data let config_msg = ConfigMessage::new(ConfigMessageType::Field, Some(config_data.clone()) ); // This will create a new IIDMessage with the serialized Config message as its payload let a_msg = config_msg.make_message(MessageType::Config); // This trait can also be used to deserialize the payload of an IIDMessage // When an config message is received it can use this trait to deserialize the payload if a_msg.msg_type() == MessageType::Config { let a_config_msg: ConfigMessage = ConfigMessage::make_self_from_string( a_msg .payload() .as_ref() .unwrap() .as_str()); // Process the config message. }
Provided methods
fn make_self_from_string<'a, T>(json_string: &'a str) -> T where
T: Sized + Deserialize<'a>,
[src]
fn make_self_from_string<'a, T>(json_string: &'a str) -> T where
T: Sized + Deserialize<'a>,
[src]This will deserialize a JSON string that is a serialized Rust struct back into the original struct
fn make_message(&self, msg_type: MessageType) -> IIDMessage where
Self: Sized + Serialize,
[src]
fn make_message(&self, msg_type: MessageType) -> IIDMessage where
Self: Sized + Serialize,
[src]This will take a struct and serialize that struct into a JSON string that will then become the payload of an IIDMesssage