riot_wrappers::gcoap

Struct PacketBuffer

Source
pub struct PacketBuffer<'b> {
    pkt: &'b mut coap_pkt_t,
    buf: *mut u8,
    len: usize,
}
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.

Fields§

§pkt: &'b mut coap_pkt_t§buf: *mut u8§len: usize

Implementations§

Source§

impl<'b> PacketBuffer<'b>

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, 'b>

Source

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

Trait Implementations§

Source§

impl<'b> Debug for PacketBuffer<'b>

Source§

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

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

impl<'b> ReadableMessage for PacketBuffer<'b>

Source§

type Code = u8

Source§

type OptionsIter<'a> = OptionsIterator<'a, 'b> where Self: 'a

Source§

type MessageOption<'a> = MessageOption<'a> where Self: '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§

fn with_static_type_annotation(&self) -> Option<RefWithStaticType<'_, Self>>

Type ID of Self or a ’static version of Self Read more
Source§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.

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