Struct coap_message_utils::inmemory_write::Message
source · pub struct Message<'a> { /* private fields */ }Expand description
A message writing into a preallocated buffer
Implementations§
source§impl<'a> Message<'a>
impl<'a> Message<'a>
pub fn new(code: &'a mut u8, tail: &'a mut [u8]) -> Self
sourcepub fn new_from_existing(code: &'a mut u8, tail: &'a mut [u8]) -> Self
pub fn new_from_existing(code: &'a mut u8, tail: &'a mut [u8]) -> Self
Create a MutableWritableMessage on a buffer that already contains a serialized message
While this is generally not useful (a parsed message has its paylod already set, and if there’s no payload, there’s no space to add options or any payload), it allows mutable access to the option bytes and the payload. This is primarily useful in situations when data is processed in place, eg. decrypted (in OSCORE), or CBOR is shifted around to get contiguous slices out of indefinite length strings.
Trait Implementations§
source§impl<'a> MinimalWritableMessage for Message<'a>
impl<'a> MinimalWritableMessage for Message<'a>
type Code = u8
type OptionNumber = u16
fn set_code(&mut self, code: u8)
fn set_payload(&mut self, payload: &[u8])
source§fn set_from_message<M>(&mut self, msg: &M)where
M: ReadableMessage,
fn set_from_message<M>(&mut self, msg: &M)where
M: ReadableMessage,
Copy code, options and payload in from a readable message Read more
source§fn add_option_str(&mut self, number: Self::OptionNumber, value: &str)
fn add_option_str(&mut self, number: Self::OptionNumber, value: &str)
Shortcut for
add_option(self, number, value.as_bytes()). Read moresource§fn add_option_uint<U>(&mut self, number: Self::OptionNumber, value: U)where
U: Ux,
fn add_option_uint<U>(&mut self, number: Self::OptionNumber, value: U)where
U: Ux,
Shortcut for
add_option on a buffer containing the uint encoded value Read moresource§impl<'a> MutableWritableMessage for Message<'a>
impl<'a> MutableWritableMessage for Message<'a>
source§fn available_space(&self) -> usize
fn available_space(&self) -> usize
Number of bytes available for additional options, payload marker and payload
source§fn payload_mut(&mut self) -> &mut [u8]
fn payload_mut(&mut self) -> &mut [u8]
👎Deprecated since 0.1.1: Use payload_mut_with_len instead
Legacy method for mutable access to the payload Read more
source§fn payload_mut_with_len(&mut self, len: usize) -> &mut [u8]
fn payload_mut_with_len(&mut self, len: usize) -> &mut [u8]
Memory-map
len bytes of the payload for writing Read moresource§fn truncate(&mut self, len: usize)
fn truncate(&mut self, len: usize)
Truncate an already-set payload to the given length; that payload must have been written to
before using
MinimalWritableMessage::set_payload, or with a suitable MutableWritableMessage::payload_mut_with_len call.source§impl<'a> ReadableMessage for Message<'a>
impl<'a> ReadableMessage for Message<'a>
§type Code = u8
type Code = u8
See code; also used with MinimalWritableMessage::set_code()
§type MessageOption<'b>
where
Self: 'b = MessageOption<'b>
type MessageOption<'b>
where
Self: 'b = MessageOption<'b>
Type of an individual option, indiciating its option number and value
§type OptionsIter<'b>
where
Self: 'b = OptionsIter<'b>
type OptionsIter<'b>
where
Self: 'b = OptionsIter<'b>
See options
source§fn options(&self) -> <Self as ReadableMessage>::OptionsIter<'_>
fn options(&self) -> <Self as ReadableMessage>::OptionsIter<'_>
Produce all options in arbitrary order as an iterator Read more