Trait MessageWrite

Source
pub trait MessageWrite: OptionInsert {
    // Required methods
    fn set_msg_type(&mut self, tt: MsgType);
    fn set_msg_id(&mut self, msg_id: MsgId);
    fn set_msg_code(&mut self, code: MsgCode);
    fn set_msg_token(&mut self, token: MsgToken);
    fn append_payload_bytes(&mut self, body: &[u8]) -> Result<(), Error>;
    fn clear(&mut self);

    // Provided methods
    fn append_payload_string(&mut self, body: &str) -> Result<(), Error> { ... }
    fn append_payload_u8(&mut self, b: u8) -> Result<(), Error> { ... }
    fn append_payload_char(&mut self, c: char) -> Result<(), Error> { ... }
}
Expand description

Trait for writing/serializing a CoAP message.

Required Methods§

Source

fn set_msg_type(&mut self, tt: MsgType)

Sets the CoAP message type. This may be called at any time during message writing without disrupting the operation. It may be called multiple times if necessary. The written value is that of the last call.

Source

fn set_msg_id(&mut self, msg_id: MsgId)

Sets the CoAP message id. This may be called at any time during message writing without disrupting the operation. It may be called multiple times if necessary. The written value is that of the last call.

Source

fn set_msg_code(&mut self, code: MsgCode)

Sets the CoAP message code. This may be called at any time during message writing without disrupting the operation. It may be called multiple times if necessary. The written value is that of the last call.

Source

fn set_msg_token(&mut self, token: MsgToken)

Sets the CoAP message token. Calling this method out-of-order will cause any previously written options or payload to be lost. It may be called multiple times if necessary. The written value is that of the last call.

Source

fn append_payload_bytes(&mut self, body: &[u8]) -> Result<(), Error>

Appends bytes from the given slice body to the payload of the message. This method should only be called after the token and all options have been set. This method may be called multiple times, each time appending data to the payload.

Source

fn clear(&mut self)

Removes the message payload along with all options.

Provided Methods§

Source

fn append_payload_string(&mut self, body: &str) -> Result<(), Error>

Appends bytes from the UTF8 representation of the given string slice body to the payload of the message. This method should only be called after the token and all options have been set. This method may be called multiple times, each time appending data to the payload.

Source

fn append_payload_u8(&mut self, b: u8) -> Result<(), Error>

Appends a single byte to the payload of the message. This method should only be called after the token and all options have been set. This method may be called multiple times, each time appending data to the payload.

Source

fn append_payload_char(&mut self, c: char) -> Result<(), Error>

Appends the UTF8 representation for a single unicode character to the payload of the message. This method should only be called after the token and all options have been set. This method may be called multiple times, each time appending data to the payload.

Trait Implementations§

Source§

impl<'a> Write for dyn MessageWrite + 'a

Source§

fn write_str(&mut self, s: &str) -> Result<(), Error>

Writes a string slice into this writer, returning whether the write succeeded. Read more
Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

impl<'a> Write for dyn MessageWrite + 'a

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Error>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<(), Error>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more

Implementors§