Skip to main content

CoapMessage

Struct CoapMessage 

Source
pub struct CoapMessage {
    pub version: u8,
    pub msg_type: CoapMessageType,
    pub code: CoapCode,
    pub message_id: u16,
    pub token: Vec<u8>,
    pub options: Vec<CoapOption>,
    pub payload: Vec<u8>,
}
Expand description

A parsed CoAP message (RFC 7252 §3).

Represents a complete CoAP datagram including the fixed header, token, options, and optional payload.

Fields§

§version: u8

Protocol version (must be 1).

§msg_type: CoapMessageType

Message type (CON, NON, ACK, RST).

§code: CoapCode

Request/response code.

§message_id: u16

Message ID for matching requests to responses.

§token: Vec<u8>

Token for correlating requests and responses (0-8 bytes).

§options: Vec<CoapOption>

CoAP options, sorted by option number.

§payload: Vec<u8>

Message payload (after the 0xFF marker).

Implementations§

Source§

impl CoapMessage

Source

pub fn parse(data: &[u8]) -> CoapResult<Self>

Parses a raw UDP datagram into a CoAP message.

RFC 7252 §3: The message format is a compact binary encoding with a 4-byte fixed header followed by a variable-length token, options, and payload.

Source

pub fn encode(&self) -> Vec<u8>

Serializes this CoAP message to bytes suitable for UDP transmission.

RFC 7252 §3: Options are encoded using delta compression relative to the previous option number.

Source

pub fn uri_path(&self) -> String

Extracts the URI path from Uri-Path options.

RFC 7252 §5.10.1: Multiple Uri-Path options are joined with / to reconstruct the full path.

Source

pub fn content_format(&self) -> Option<u16>

Returns the Content-Format option value, if present.

Source

pub fn block1(&self) -> Option<BlockOption>

Returns the Block1 option, if present.

Source

pub fn block2(&self) -> Option<BlockOption>

Returns the Block2 option, if present.

Trait Implementations§

Source§

impl Clone for CoapMessage

Source§

fn clone(&self) -> CoapMessage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CoapMessage

Source§

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

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

impl PartialEq for CoapMessage

Source§

fn eq(&self, other: &CoapMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CoapMessage

Source§

impl StructuralPartialEq for CoapMessage

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.