Struct Message

Source
pub struct Message {
    pub channel: u64,
    pub typ: u8,
    pub message: Vec<u8>,
}
Expand description

A SMC message.

Fields§

§channel: u64§typ: u8§message: Vec<u8>

Implementations§

Source§

impl Message

Source

pub fn new(channel: u64, typ: u8, message: Vec<u8>) -> Message

Create a new message.

Examples found in repository?
examples/send.rs (line 12)
8async fn send() -> io::Result<()> {
9    let stdout = io::stdout().lock().await;
10    let mut writer = Writer::new(stdout);
11    for i in 0..3 {
12        let message = Message::new(i, 1, "hi".as_bytes().to_vec());
13        print_msg(&message);
14        writer.send(message).await?;
15    }
16    Ok(())
17}
More examples
Hide additional examples
examples/tcp.rs (line 100)
97async fn handle_outgoing(stream: TcpStream) -> Result<()> {
98    let (mut reader, mut writer) = create_from_stream(stream);
99
100    let hello_msg = Message::new(1, 1, "hi".as_bytes().to_vec());
101    writer.send(hello_msg).await?;
102
103    while let Some(msg) = reader.try_next().await? {
104        eprintln!("received: {}", format_msg(&msg));
105    }
106
107    Ok(())
108}
Source

pub fn from_buf(buf: &[u8]) -> Result<Message, Error>

Decode a message from buf (bytes).

Note: buf has to have a valid length, and the length prefix has to be removed already.

Source

pub fn encode(&self) -> Result<Vec<u8>, Error>

Encode a message body into a buffer.

The result can be sent directly over any medium. It is length-prefixed, so chunking should not be an issue.

Trait Implementations§

Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.