Struct mles_utils::ResyncMsg

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

ResyncMsg structure

This structure defines resynchronization Msg structure that can be used to resynchronize history state to root server from peers. The resynchronization message can be sent only during initial connection message and packs the history into one message that can be taken into account by Mles root server.

Implementations

Create a new ResyncMsg object with encoded message vector.

Example
use mles_utils::{Msg, ResyncMsg};

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.encode();
let vec = vec![msg];
let rmsg = ResyncMsg::new(&vec);

Get the length of the resync message vector

Example
use mles_utils::{Msg, ResyncMsg};

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.encode();
let vec = vec![msg];
let rmsg = ResyncMsg::new(&vec);
assert_eq!(1, rmsg.len());

Get all items of the resync message vector

Example
use mles_utils::{Msg, ResyncMsg};

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.encode();
let vec = vec![msg];
let rmsg = ResyncMsg::new(&vec);
let rvec = rmsg.get_messages();
assert_eq!(vec[0], rvec[0]);

Encode ResyncMsg object to CBOR.

Errors

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

Example
use mles_utils::{ResyncMsg, Msg};

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.encode();
let vec = vec![msg];
let rmsg = ResyncMsg::new(&vec);
let encoded_msg: Vec<u8> = rmsg.encode();

Decode CBOR byte string to ResyncMsg object.

Errors

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

Example
use mles_utils::{ResyncMsg, Msg};

let msg = Msg::new("My uid".to_string(), "My channel".to_string(), Vec::new());
let msg = msg.encode();
let vec = vec![msg];
let rmsg = ResyncMsg::new(&vec);
let encoded_msg: Vec<u8> = rmsg.encode();
let decoded_msg: ResyncMsg = ResyncMsg::decode(&encoded_msg);
assert_eq!(1, decoded_msg.len());

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.