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: u8Protocol version (must be 1).
msg_type: CoapMessageTypeMessage type (CON, NON, ACK, RST).
code: CoapCodeRequest/response code.
message_id: u16Message 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
impl CoapMessage
Sourcepub fn parse(data: &[u8]) -> CoapResult<Self>
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.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn uri_path(&self) -> String
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.
Sourcepub fn content_format(&self) -> Option<u16>
pub fn content_format(&self) -> Option<u16>
Returns the Content-Format option value, if present.
Sourcepub fn block1(&self) -> Option<BlockOption>
pub fn block1(&self) -> Option<BlockOption>
Returns the Block1 option, if present.
Sourcepub fn block2(&self) -> Option<BlockOption>
pub fn block2(&self) -> Option<BlockOption>
Returns the Block2 option, if present.
Trait Implementations§
Source§impl Clone for CoapMessage
impl Clone for CoapMessage
Source§fn clone(&self) -> CoapMessage
fn clone(&self) -> CoapMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more