pub struct PacketBuffer<'b> {
pkt: &'b mut coap_pkt_t,
buf: *mut u8,
len: usize,
}
riot_module_gcoap
only.Expand description
A representation of the incoming or outgoing data on the server side of a request. This includes the coap_pkt_t pre-parsed header and option pointers as well as the memory area dedicated to returning the packet.
This struct wraps the unsafety of the C API, but does not structurally ensure that valid CoAP messages are created. (For example, it does not keep the user from adding options after the payload marker). Use CoAP generalization for that.
Fields§
§pkt: &'b mut coap_pkt_t
§buf: *mut u8
§len: usize
Implementations§
Source§impl<'b> PacketBuffer<'b>
impl<'b> PacketBuffer<'b>
Sourcepub fn get_code_raw(&self) -> u8
pub fn get_code_raw(&self) -> u8
Wrapper for coap_get_code_raw
Sourcepub fn resp_init(&mut self, code: u8) -> Result<(), NumericError>
pub fn resp_init(&mut self, code: u8) -> Result<(), NumericError>
Wrapper for gcoap_resp_init
As it is used and wrapped here, this makes GCOAP_RESP_OPTIONS_BUF bytes unusable, but working around that would mean duplicating code. Just set GCOAP_RESP_OPTIONS_BUF to zero to keep the overhead low.
pub fn set_code_raw(&mut self, code: u8)
Sourcepub fn get_length(&self, payload_used: usize) -> usize
pub fn get_length(&self, payload_used: usize) -> usize
Return the total number of bytes in the message, given that payload_used
bytes were
written at the payload pointer. Note that those bytes have to include the payload marker.
This measures the distance between the payload pointer in the pkt and the start of the
buffer. It is the header length after prepare_response
, and grows as options are added.
Sourcepub fn payload(&self) -> &[u8]
pub fn payload(&self) -> &[u8]
A view of the current message payload
This is only the CoAP payload after opt_finish has been called; before, it is a view on the remaining buffer space after any options that have already been added.
Sourcepub fn payload_mut(&mut self) -> &mut [u8]
pub fn payload_mut(&mut self) -> &mut [u8]
A mutable view of the current message payload
See payload
.
Sourcepub fn opt_add_uint(
&mut self,
optnum: u16,
value: u32,
) -> Result<(), NumericError>
pub fn opt_add_uint( &mut self, optnum: u16, value: u32, ) -> Result<(), NumericError>
Add an integer value as an option
Sourcepub fn opt_add_opaque(
&mut self,
optnum: u16,
data: &[u8],
) -> Result<(), NumericError>
pub fn opt_add_opaque( &mut self, optnum: u16, data: &[u8], ) -> Result<(), NumericError>
Add a binary value as an option
pub fn opt_iter<'a>(&'a self) -> PacketBufferOptIter<'a, 'b> ⓘ
pub fn opt_iter_mut<'a>(&'a mut self) -> PacketBufferOptIterMut<'a, 'b> ⓘ
Trait Implementations§
Source§impl<'b> Debug for PacketBuffer<'b>
impl<'b> Debug for PacketBuffer<'b>
Source§impl<'b> ReadableMessage for PacketBuffer<'b>
impl<'b> ReadableMessage for PacketBuffer<'b>
Source§type Code = u8
type Code = u8
Self::code()
Source§type OptionsIter<'a> = OptionsIterator<'a, 'b>
where
Self: 'a
type OptionsIter<'a> = OptionsIterator<'a, 'b> where Self: 'a
Self::options()
Source§type MessageOption<'a> = MessageOption<'a>
where
Self: 'a
type MessageOption<'a> = MessageOption<'a> where Self: 'a
Source§fn code(&self) -> Self::Code
fn code(&self) -> Self::Code
Source§fn options(&self) -> Self::OptionsIter<'_>
fn options(&self) -> Self::OptionsIter<'_>
Source§fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>
impl<'b> WithSortedOptions for PacketBuffer<'b>
Auto Trait Implementations§
impl<'b> Freeze for PacketBuffer<'b>
impl<'b> RefUnwindSafe for PacketBuffer<'b>
impl<'b> !Send for PacketBuffer<'b>
impl<'b> !Sync for PacketBuffer<'b>
impl<'b> Unpin for PacketBuffer<'b>
impl<'b> !UnwindSafe for PacketBuffer<'b>
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<T> IntoSwitch for T
impl<T> IntoSwitch for T
Source§fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>
fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>
Source§fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>where
Self: Sized,
fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>where
Self: Sized,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 12 bytes