pub struct GenericMessage<EM: EncodedMessage> { /* private fields */ }
Expand description
A message writing into a preallocated buffer
Implementations§
Source§impl<'a> GenericMessage<SliceMessage<'a>>
A CoAP messag that resides in contiguous mutable memory
impl<'a> GenericMessage<SliceMessage<'a>>
A CoAP messag that resides in contiguous mutable memory
Exceeding the guarantees of MutableWritableMessage, this does allow some out-of-sequence invocations: Even after payload has been written to, options can be added, memmove’ing (right-rotating) the written payload, possibly truncating it out of the buffer. This is needed to accommodate libOSCORE’s requirements (because while libOSCORE can also do without a memmove-ing message, that’d require its use through WritableMessage to adhere to in-OSCORE write sequence conventions, making the whole situation no easier on the coap-message abstraction). Data will only be moved if an option is added after content has been set, so this comes at no runtime cost for those who do not need it. (It may be later turned into a feature. Then, the memmove code would be removed; carrying the latest option number in the WriteState should come at no extra cost due to the struct’s content and alignment).
When viewed through the coap_message::ReadableMessage trait, this will behave as if writing had stopped (but still allows writes after reading); in particular, the payload will be shown as empty. (This may be obvious from most points of view, but when coming from a [coap_message::WritableMessage] point of view where payloads can only ever be truncated and not made longer, this clarification is relevant).
The type is covariant over its lifetime. This also means that we can never add any methods
where we move references into Self, but we don’t do this: The lifetime 'a
only serves to
describe the memory backing it; data is moved in there, not stored by reference.
FIXME: The covaraint property is not available through … how would it even be made available?
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.
This uses the same strategy for errors as crate::inmemory::Message: Validation happens incrementally.
pub fn downcast_from<M: MinimalWritableMessage>( generic: &'a mut M, ) -> Option<&'a mut Self>
downcast
only.Source§impl<T: EncodedMessage> GenericMessage<T>
impl<T: EncodedMessage> GenericMessage<T>
pub fn new_from_empty_encoded(encoded: T) -> Self
Source§impl<EM: EncodedMessage> GenericMessage<EM>
impl<EM: EncodedMessage> GenericMessage<EM>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Discard anything that has been written in the message, and allow any operation that would
be allowed after calling Self::new()
.
This is a short-cut to messages that can be snapshotted and rewound, and a band-aid until that is available in traits.
Trait Implementations§
Source§impl<EM: EncodedMessage> Debug for GenericMessage<EM>
impl<EM: EncodedMessage> Debug for GenericMessage<EM>
Source§impl<EM: EncodedMessage> Format for GenericMessage<EM>
Available on crate feature defmt
only.
impl<EM: EncodedMessage> Format for GenericMessage<EM>
defmt
only.Source§impl<EM: EncodedMessage> MinimalWritableMessage for GenericMessage<EM>
impl<EM: EncodedMessage> MinimalWritableMessage for GenericMessage<EM>
Source§type Code = u8
type Code = u8
Self::set_code()
Source§type OptionNumber = u16
type OptionNumber = u16
Source§type UnionError = WriteError
type UnionError = WriteError
Code
and OptionNumber
, can be .into()
ed. Read moreSource§type AddOptionError = WriteError
type AddOptionError = WriteError
Source§type SetPayloadError = WriteError
type SetPayloadError = WriteError
Source§fn set_code(&mut self, code: u8)
fn set_code(&mut self, code: u8)
Source§fn add_option(&mut self, number: u16, data: &[u8]) -> Result<(), WriteError>
fn add_option(&mut self, number: u16, data: &[u8]) -> Result<(), WriteError>
Source§fn set_payload(&mut self, payload: &[u8]) -> Result<(), WriteError>
fn set_payload(&mut self, payload: &[u8]) -> Result<(), WriteError>
Source§fn with_static_type_annotation(
&mut self,
) -> Option<RefMutWithStaticType<'_, Self>>
fn with_static_type_annotation( &mut self, ) -> Option<RefMutWithStaticType<'_, Self>>
Source§fn promote_to_mutable_writable_message(&mut self) -> Option<&mut Self>
fn promote_to_mutable_writable_message(&mut self) -> Option<&mut Self>
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,
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>
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>
add_option
on a buffer containing the uint encoded value Read moreSource§fn convert_code_error(e: <Self::Code as Code>::Error) -> Self::UnionError
fn convert_code_error(e: <Self::Code as Code>::Error) -> Self::UnionError
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
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
Self::AddOptionError
Read moreSource§fn convert_set_payload_error(e: Self::SetPayloadError) -> Self::UnionError
fn convert_set_payload_error(e: Self::SetPayloadError) -> Self::UnionError
Self::SetPayloadError
Read moreSource§impl<EM: EncodedMessage> MutableWritableMessage for GenericMessage<EM>
impl<EM: EncodedMessage> MutableWritableMessage for GenericMessage<EM>
Source§fn available_space(&self) -> usize
fn available_space(&self) -> usize
Source§fn payload_mut_with_len(&mut self, len: usize) -> Result<&mut [u8], WriteError>
fn payload_mut_with_len(&mut self, len: usize) -> Result<&mut [u8], WriteError>
len
bytes of the payload for writing Read moreSource§fn truncate(&mut self, len: usize) -> Result<(), WriteError>
fn truncate(&mut self, len: usize) -> Result<(), WriteError>
MinimalWritableMessage::set_payload
, or with a suitable MutableWritableMessage::payload_mut_with_len
call.Source§impl<EM: EncodedMessage> ReadableMessage for GenericMessage<EM>
impl<EM: EncodedMessage> ReadableMessage for GenericMessage<EM>
Source§type Code = u8
type Code = u8
Self::code()
Source§type MessageOption<'b> = MessageOption<'b>
where
Self: 'b
type MessageOption<'b> = MessageOption<'b> where Self: 'b
Source§type OptionsIter<'b> = OptionsIter<'b>
where
Self: 'b
type OptionsIter<'b> = OptionsIter<'b> where Self: 'b
Self::options()
Source§fn options(&self) -> <Self as ReadableMessage>::OptionsIter<'_>
fn options(&self) -> <Self as ReadableMessage>::OptionsIter<'_>
Source§fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
impl<EM: EncodedMessage> WithSortedOptions for GenericMessage<EM>
Auto Trait Implementations§
impl<EM> Freeze for GenericMessage<EM>where
EM: Freeze,
impl<EM> RefUnwindSafe for GenericMessage<EM>where
EM: RefUnwindSafe,
impl<EM> Send for GenericMessage<EM>where
EM: Send,
impl<EM> Sync for GenericMessage<EM>where
EM: Sync,
impl<EM> Unpin for GenericMessage<EM>where
EM: Unpin,
impl<EM> UnwindSafe for GenericMessage<EM>where
EM: UnwindSafe,
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
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>
core::fmt::Debug
imlementation, and also provide
[defmt_0_3::Format
] if the defmt_0_3
feature is selected. Read more