pub struct HeapMessage { /* private fields */ }
Available on crate feature
alloc
only.Expand description
A heap CoAP message backed by allocated memory
It stores its payload in a Vec
, and uses a BTreeMap<_, Vec<_>>
to
store all the individual option values.
It offers a few methods for direct manipulation of options, even out of sequence, that can not be expected from a general message buffer and are thus not captured in traits.
use coap_message::{MinimalWritableMessage, ReadableMessage};
let mut m = HeapMessage::new();
m.set_code(1);
m.add_option(11, b".well-known");
m.add_option(11, b"core");
let mut m2 = HeapMessage::new();
m2.set_from_message(&m);
assert!(m.code() == 1);
Implementations§
Source§impl HeapMessage
impl HeapMessage
pub fn new() -> Self
Sourcepub fn change_option(
&mut self,
optnum: u16,
occurrence: usize,
value: impl Into<Vec<u8>>,
)
pub fn change_option( &mut self, optnum: u16, occurrence: usize, value: impl Into<Vec<u8>>, )
Replace the occurrence’th value of the optnum option in the message
Panics if there’s not occurrence + 1
options of that number.
Sourcepub fn remove_option(&mut self, optnum: u16, occurrence: usize)
pub fn remove_option(&mut self, optnum: u16, occurrence: usize)
Remove the occurrence’th option of option number optnum
Panics if there’s not occurrence + 1
options of that number.
Trait Implementations§
Source§impl Debug for HeapMessage
impl Debug for HeapMessage
Source§impl MinimalWritableMessage for HeapMessage
impl MinimalWritableMessage for HeapMessage
Source§type AddOptionError = Infallible
type AddOptionError = Infallible
Error returned when an option can not be added (eg. for lack of space, or because an option
of a higher number or even the payload was already set)
Source§type SetPayloadError = Infallible
type SetPayloadError = Infallible
Error returned when setting the payload (eg. for lack of space, or when a message of that
type does not take a payload)
Source§type UnionError = Infallible
type UnionError = Infallible
Error type into which either of the other errors, as well as the errors for conversion of
the
Code
and OptionNumber
, can be .into()
ed. Read moreSource§type Code = u8
type Code = u8
See
Self::set_code()
Source§type OptionNumber = u16
type OptionNumber = u16
Source§fn set_code(&mut self, code: u8)
fn set_code(&mut self, code: u8)
Set the CoAP code of the message (in a request, that is the request method)
Source§fn add_option(&mut self, optnum: u16, data: &[u8]) -> Result<(), Infallible>
fn add_option(&mut self, optnum: u16, data: &[u8]) -> Result<(), Infallible>
Add an option to the message Read more
Source§fn set_payload(&mut self, payload: &[u8]) -> Result<(), Infallible>
fn set_payload(&mut self, payload: &[u8]) -> Result<(), Infallible>
Set the payload to the message Read more
Source§fn set_from_message<M>(&mut self, msg: &M) -> Result<(), Self::UnionError>where
M: ReadableMessage + WithSortedOptions,
fn set_from_message<M>(&mut self, msg: &M) -> Result<(), Self::UnionError>where
M: ReadableMessage + WithSortedOptions,
Copy code, options and payload in from a readable message
Source§fn add_option_str(
&mut self,
number: Self::OptionNumber,
value: &str,
) -> Result<(), Self::AddOptionError>
fn add_option_str( &mut self, number: Self::OptionNumber, value: &str, ) -> Result<(), Self::AddOptionError>
Shortcut for
add_option(self, number, value.as_bytes())
. Read moreSource§fn add_option_uint<U>(
&mut self,
number: Self::OptionNumber,
value: U,
) -> Result<(), Self::AddOptionError>
fn add_option_uint<U>( &mut self, number: Self::OptionNumber, value: U, ) -> Result<(), Self::AddOptionError>
Shortcut for
add_option
on a buffer containing the uint encoded value Read moreSource§fn with_static_type_annotation(
&mut self,
) -> Option<RefMutWithStaticType<'_, Self>>
fn with_static_type_annotation( &mut self, ) -> Option<RefMutWithStaticType<'_, Self>>
Type ID of Self or a ’static version of Self Read more
Source§fn promote_to_mutable_writable_message(
&mut self,
) -> Option<&mut (impl MinimalWritableMessage<Code = Self::Code, OptionNumber = Self::OptionNumber, AddOptionError = Self::AddOptionError, SetPayloadError = Self::SetPayloadError, UnionError = Self::UnionError> + MutableWritableMessage)>
fn promote_to_mutable_writable_message( &mut self, ) -> Option<&mut (impl MinimalWritableMessage<Code = Self::Code, OptionNumber = Self::OptionNumber, AddOptionError = Self::AddOptionError, SetPayloadError = Self::SetPayloadError, UnionError = Self::UnionError> + MutableWritableMessage)>
Tries to obtain a MutableWritableMessage from self. Read more
Source§fn convert_code_error(e: <Self::Code as Code>::Error) -> Self::UnionError
fn convert_code_error(e: <Self::Code as Code>::Error) -> Self::UnionError
Auxiliary function for converting
Self::Code::Error
Read moreSource§fn convert_option_number_error(
e: <Self::OptionNumber as OptionNumber>::Error,
) -> Self::UnionError
fn convert_option_number_error( e: <Self::OptionNumber as OptionNumber>::Error, ) -> Self::UnionError
Auxiliary function for converting
Self::OptionNumber::Error
Read moreSource§fn convert_add_option_error(e: Self::AddOptionError) -> Self::UnionError
fn convert_add_option_error(e: Self::AddOptionError) -> Self::UnionError
Auxiliary function for converting
Self::AddOptionError
Read moreSource§fn convert_set_payload_error(e: Self::SetPayloadError) -> Self::UnionError
fn convert_set_payload_error(e: Self::SetPayloadError) -> Self::UnionError
Auxiliary function for converting
Self::SetPayloadError
Read moreSource§impl MutableWritableMessage for HeapMessage
impl MutableWritableMessage for HeapMessage
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_with_len(&mut self, len: usize) -> Result<&mut [u8], Infallible>
fn payload_mut_with_len(&mut self, len: usize) -> Result<&mut [u8], Infallible>
Memory-map
len
bytes of the payload for writing Read moreSource§fn truncate(&mut self, len: usize) -> Result<(), Infallible>
fn truncate(&mut self, len: usize) -> Result<(), Infallible>
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§fn mutate_options<F>(&mut self, callback: F)
fn mutate_options<F>(&mut self, callback: F)
Apply a callback to all options in sequence Read more
Source§impl ReadableMessage for HeapMessage
impl ReadableMessage for HeapMessage
Source§type Code = u8
type Code = u8
See
Self::code()
Source§type MessageOption<'a> = MessageOption<'a>
type MessageOption<'a> = MessageOption<'a>
Type of an individual option, indiciating its option number and value
Source§type OptionsIter<'a> = ReadCursor<'a>
type OptionsIter<'a> = ReadCursor<'a>
See
Self::options()
Source§fn options<'m>(&'m self) -> ReadCursor<'m> ⓘ
fn options<'m>(&'m self) -> ReadCursor<'m> ⓘ
Produce all options in arbitrary order as an iterator Read more
Source§fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
Type ID of Self or a ’static version of Self Read more
impl SeekWritableMessage for HeapMessage
impl WithSortedOptions for HeapMessage
Auto Trait Implementations§
impl Freeze for HeapMessage
impl RefUnwindSafe for HeapMessage
impl Send for HeapMessage
impl Sync for HeapMessage
impl Unpin for HeapMessage
impl UnwindSafe for HeapMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<M> ShowMessageExt for Mwhere
M: ReadableMessage,
impl<M> ShowMessageExt for Mwhere
M: ReadableMessage,
Source§fn show(&self) -> ShowMessage<'_, Self>
fn show(&self) -> ShowMessage<'_, Self>
Wraps the message to have a
core::fmt::Debug
imlementation, and also provide
[defmt_0_3::Format
] if the defmt_0_3
feature is selected. Read more