Struct mles_utils::Msg

source ·
pub struct Msg { /* private fields */ }
Expand description

Msg structure

This structure defines the Mles interface value triplet (uid, channel, message). It is eventually serialized and deserialized by CBOR.

Implementations

Create a new Msg object with value triplet.

Example
use mles_utils::Msg;

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());

Set uid for Msg object.

Example
use mles_utils::Msg;

let mut msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.set_uid("New uid".to_string());

assert_eq!("New uid".to_string(), *msg.get_uid());

Set channel for Msg object.

Example
use mles_utils::Msg;

let mut msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.set_channel("New channel".to_string());

assert_eq!("New channel".to_string(), *msg.get_channel());

Set message for Msg object.

Example
use mles_utils::Msg;

let mut msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let new_message: Vec<u8> = "New message".to_string().into_bytes();
let msg = msg.set_message(new_message);

Get uid for Msg object. See example for set uid.

Get channel for Msg object. See example for set channel.

Get message for Msg object.

Example
use mles_utils::Msg;

let mut msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg: &Vec<u8> = msg.get_message();

Get message len for Msg object.

Example
use mles_utils::Msg;

let mut msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg_len: usize = msg.get_message_len();

Encode Msg object to CBOR.

Errors

If message cannot be encoded, an empty vector is returned.

Example
use mles_utils::Msg;

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let encoded_msg: Vec<u8> = msg.encode();

Decode CBOR byte string to Msg object.

Errors

If message cannot be decoded, a Msg structure with empty items is returned.

Example
use mles_utils::Msg;

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let encoded_msg: Vec<u8> = msg.encode();
let decoded_msg: Msg = Msg::decode(&encoded_msg);

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.