Struct coap_message::heapmessage::HeapMessage
source · [−]pub struct HeapMessage { /* private fields */ }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.
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
sourceimpl 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
sourceimpl Debug for HeapMessage
impl Debug for HeapMessage
sourceimpl MinimalWritableMessage for HeapMessage
impl MinimalWritableMessage for HeapMessage
type Code = u8
type OptionNumber = u16
fn set_code(&mut self, code: u8)
fn set_payload(&mut self, payload: &[u8])
sourcefn 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
sourcefn 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 more
sourcefn add_option_uint<U: Ux>(&mut self, number: Self::OptionNumber, value: U)
fn add_option_uint<U: Ux>(&mut self, number: Self::OptionNumber, value: U)
Shortcut for add_option on a buffer containing the uint encoded value Read more
sourceimpl MutableWritableMessage for HeapMessage
impl MutableWritableMessage for HeapMessage
sourcefn available_space(&self) -> usize
fn available_space(&self) -> usize
Number of bytes available for additional options, payload marker and payload
sourcefn payload_mut(&mut self) -> &mut [u8]
fn payload_mut(&mut self) -> &mut [u8]
Use payload_mut_with_len instead
Legacy method for mutable access to the payload Read more
sourcefn 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 more
sourcefn 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. Read more
sourcefn mutate_options<F>(&mut self, callback: F) where
F: FnMut(Self::OptionNumber, &mut [u8]),
fn mutate_options<F>(&mut self, callback: F) where
F: FnMut(Self::OptionNumber, &mut [u8]),
Apply a callback to all options in sequence Read more
sourceimpl ReadableMessage for HeapMessage
impl ReadableMessage for HeapMessage
type Code = u8
type Code = u8
See code; also used with MinimalWritableMessage::set_code()
type MessageOption = MessageOption<'a>
type MessageOption = MessageOption<'a>
Type of an individual option, indiciating its option number and value
type OptionsIter = ReadCursor<'a>
type OptionsIter = ReadCursor<'a>
See options
sourcefn options<'m>(&'m self) -> ReadCursor<'m>ⓘNotable traits for ReadCursor<'a>impl<'a> Iterator for ReadCursor<'a> type Item = MessageOption<'a>;
fn options<'m>(&'m self) -> ReadCursor<'m>ⓘNotable traits for ReadCursor<'a>impl<'a> Iterator for ReadCursor<'a> type Item = MessageOption<'a>;
Produce all options in arbitrary order as an iterator Read more
impl WithSortedOptions for HeapMessage
Auto Trait Implementations
impl RefUnwindSafe for HeapMessage
impl Send for HeapMessage
impl Sync for HeapMessage
impl Unpin for HeapMessage
impl UnwindSafe for HeapMessage
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more