pub struct PacketBuffer { /* private fields */ }
Available on 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.

Implementations§

source§

impl PacketBuffer

source

pub fn get_code_raw(&self) -> u8

Wrapper for coap_get_code_raw

source

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.

source

pub fn set_code_raw(&mut self, code: u8)

source

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.

source

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.

source

pub fn payload_mut(&mut self) -> &mut [u8]

A mutable view of the current message payload

See payload.

source

pub fn opt_add_uint( &mut self, optnum: u16, value: u32 ) -> Result<(), NumericError>

Add an integer value as an option

source

pub fn opt_add_opaque( &mut self, optnum: u16, data: &[u8] ) -> Result<(), NumericError>

Add a binary value as an option

source

pub fn opt_iter<'a>(&'a self) -> PacketBufferOptIter<'a>

source

pub fn opt_iter_mut<'a>(&'a mut self) -> PacketBufferOptIterMut<'a>

Trait Implementations§

source§

impl Debug for PacketBuffer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ReadableMessage for PacketBuffer

§

type Code = u8

§

type OptionsIter<'a> = OptionsIterator<'a>

§

type MessageOption<'a> = MessageOption<'a>

Type of an individual option, indiciating its option number and value
source§

fn code(&self) -> Self::Code

Get the code (request method or response code) of the message Read more
source§

fn payload(&self) -> &[u8]

Get the payload set in the message Read more
source§

fn options(&self) -> Self::OptionsIter<'_>

Produce all options in arbitrary order as an iterator Read more
source§

impl ReadableMessage for PacketBuffer

§

type Code = u8

§

type OptionsIter<'a> = OptionsIterator<'a>

§

type MessageOption<'a> = MessageOption<'a>

Type of an individual option, indiciating its option number and value
source§

fn code(&self) -> Self::Code

Get the code (request method or response code) of the message Read more
source§

fn payload(&self) -> &[u8]

Get the payload set in the message Read more
source§

fn options(&self) -> Self::OptionsIter<'_>

Produce all options in arbitrary order as an iterator Read more
source§

impl WithSortedOptions for PacketBuffer

source§

impl WithSortedOptions for PacketBuffer

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoSwitch for T

source§

fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
source§

fn into_active_low_switch(self) -> Switch<Self, ActiveLow>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
source§

fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.