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§
Sourcefn set_msg_type(&mut self, tt: MsgType)
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.
Sourcefn set_msg_id(&mut self, msg_id: MsgId)
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.
Sourcefn set_msg_code(&mut self, code: MsgCode)
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.
Sourcefn set_msg_token(&mut self, token: MsgToken)
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.
Sourcefn append_payload_bytes(&mut self, body: &[u8]) -> Result<(), Error>
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.
Provided Methods§
Sourcefn append_payload_string(&mut self, body: &str) -> Result<(), Error>
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.
Sourcefn append_payload_u8(&mut self, b: u8) -> Result<(), Error>
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.
Sourcefn append_payload_char(&mut self, c: char) -> Result<(), Error>
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
impl<'a> Write for dyn MessageWrite + 'a
Source§impl<'a> Write for dyn MessageWrite + 'a
impl<'a> Write for dyn MessageWrite + 'a
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)