[][src]Struct mles_utils::Msg

pub struct Msg { /* fields omitted */ }

Msg structure

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

Implementations

impl Msg[src]

pub fn new(uid: String, channel: String, message: Vec<u8>) -> Msg[src]

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());

pub fn set_uid(self, uid: String) -> Msg[src]

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());

pub fn set_channel(self, channel: String) -> Msg[src]

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());

pub fn set_message(self, message: Vec<u8>) -> Msg[src]

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);

pub fn get_uid(&self) -> &String[src]

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

pub fn get_channel(&self) -> &String[src]

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

pub fn get_message(&self) -> &Vec<u8>[src]

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();

pub fn get_message_len(&self) -> usize[src]

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();

pub fn get_mut_message(&mut self) -> &mut Vec<u8>[src]

Get mutable message reference for Msg object.

Example

use mles_utils::Msg;

let mut msg = Msg::new("My uid".to_string(), "My channel".to_string(), "My
message".to_string().into_bytes());
let message = msg.get_mut_message();
message.extend_from_slice(&" is mutable".to_string().into_bytes());

pub fn encode(&self) -> Vec<u8>[src]

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();

pub fn decode(slice: &[u8]) -> Msg[src]

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

impl Clone for Msg[src]

impl Debug for Msg[src]

impl<'de> Deserialize<'de> for Msg[src]

impl Serialize for Msg[src]

Auto Trait Implementations

impl RefUnwindSafe for Msg

impl Send for Msg

impl Sync for Msg

impl Unpin for Msg

impl UnwindSafe for Msg

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.