unicoap_message_t Struct Reference

Generic CoAP message. More...

Detailed Description

Generic CoAP message.

The payload of this message can either be represented as a vector (iolist_t) or a buffer. You use unicoap_message_payload_get and unicoap_message_payload_set to work with contiguous payloads. For iolists, refer to unicoap_message_payload_get_chunks, unicoap_message_payload_set_chunks, and unicoap_message_payload_append_chunk.

Regardless of the representation, you can always use unicoap_message_payload_get_size. For vectored payload, this entails an overhead of O(n). If you just want to check whether there is any payload, use unicoap_message_payload_is_empty. You can also make the payload contiguous by calling unicoap_message_payload_make_contiguous, which mutates the message struct. If you purely want to obtain a contiguous representation stored in another buffer, use unicoap_message_payload_copy.

Definition at line 75 of file message.h.

#include <message.h>

Data Fields

unicoap_options_toptions
 Message options. More...
 
union {
   struct {
      uint8_t *   payload
 Message payload. More...
 
      size_t   payload_size
 Size of message payload. More...
 
   } 
 Contiguous payload.
 
   iolist_t *   payload_chunks
 Noncontiguous payload. More...
 
}; 
 Payload representation.
 
union {
   uint8_t   code
 CoAP message code. More...
 
   unicoap_method_t   method
 CoAP request method. More...
 
   unicoap_status_t   status
 CoAP response status. More...
 
   unicoap_signal_t   signal
 CoAP signal. More...
 
}; 
 
unicoap_payload_representation_t payload_representation: 1
 A value indicating how the payload is represented. More...
 

CoAP message

static uint8_t * unicoap_message_payload_get (unicoap_message_t *message)
 Retrieves contiguous message payload, if available. More...
 
static void unicoap_message_payload_set (unicoap_message_t *message, uint8_t *payload, size_t size)
 Assigns the given message a contiguous payload. More...
 
static iolist_tunicoap_message_payload_get_chunks (unicoap_message_t *message)
 Retrieves noncontiguous message payload, if available. More...
 
static void unicoap_message_payload_set_chunks (unicoap_message_t *message, iolist_t *chunks)
 Assigns the given message a noncontiguous payload. More...
 
void unicoap_message_payload_append_chunk (unicoap_message_t *message, iolist_t *chunk)
 Appends a payload chunk to a message. More...
 
static size_t unicoap_message_payload_get_size (const unicoap_message_t *message)
 Retrieves payload size, regardless of payload representation. More...
 
bool unicoap_message_payload_is_empty (const unicoap_message_t *message)
 Determines whether message has any payload. More...
 
ssize_t unicoap_message_payload_copy (const unicoap_message_t *message, uint8_t *buffer, size_t capacity)
 Copies payload into given buffer. More...
 
ssize_t unicoap_message_payload_make_contiguous (unicoap_message_t *message, uint8_t *buffer, size_t capacity)
 Copies noncontiguous payload into contiguous storage buffer. More...
 
static uint8_t * unicoap_message_options_data (const unicoap_message_t *message)
 Retrieves options storage buffer. More...
 
static size_t unicoap_message_options_size (const unicoap_message_t *message)
 Retrieves total size of options in buffer. More...
 

Message initializers

static void unicoap_message_init_empty (unicoap_message_t *message, uint8_t code)
 Initializes message with no payload and no options. More...
 
static void unicoap_message_init (unicoap_message_t *message, uint8_t code, uint8_t *payload, size_t payload_size)
 Initializes message with payload but no options. More...
 
static void unicoap_message_init_string (unicoap_message_t *message, uint8_t code, const char *payload)
 Initializes message with payload from null-terminated UTF-8 string but no options. More...
 
static void unicoap_message_init_with_options (unicoap_message_t *message, uint8_t code, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
 Initializes message with byte payload and options. More...
 
static void unicoap_message_init_string_with_options (unicoap_message_t *message, uint8_t code, const char *payload, unicoap_options_t *options)
 Initializes message with payload from null-terminated UTF-8 string and options. More...
 

Signaling messages

static unicoap_signal_t unicoap_message_get_signal (const unicoap_message_t *message)
 Retrieves signal code from given signal message. More...
 
static void unicoap_message_set_signal (unicoap_message_t *message, unicoap_signal_t signal)
 Sets signal code of given signal message. More...
 

Request messages

static unicoap_method_t unicoap_request_get_method (const unicoap_message_t *request)
 Obtains request method from the given message's code. More...
 
static void unicoap_request_set_method (unicoap_message_t *request, unicoap_method_t method)
 Sets request method. More...
 
static void unicoap_request_init_empty (unicoap_message_t *request, unicoap_method_t method)
 Initializes request with no payload and no options. More...
 
static void unicoap_request_init (unicoap_message_t *request, unicoap_method_t method, uint8_t *payload, size_t payload_size)
 Initializes request with payload but no options. More...
 
static void unicoap_request_init_string (unicoap_message_t *request, unicoap_method_t method, const char *payload)
 Initializes request with payload from null-terminated UTF-8 string but no options. More...
 
static void unicoap_request_init_with_options (unicoap_message_t *request, unicoap_method_t method, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
 Initializes request with byte payload and options. More...
 
static void unicoap_request_init_string_with_options (unicoap_message_t *request, unicoap_method_t method, const char *payload, unicoap_options_t *options)
 Initializes request with payload from null-terminated UTF-8 string and options. More...
 

Response messages

static unicoap_status_t unicoap_response_get_status (const unicoap_message_t *response)
 Obtains response status from the given message's code. More...
 
static void unicoap_response_set_status (unicoap_message_t *response, unicoap_status_t status)
 Sets response status. More...
 
static void unicoap_response_init_empty (unicoap_message_t *response, unicoap_status_t status)
 Initializes response with no payload and no options. More...
 
static void unicoap_response_init (unicoap_message_t *response, unicoap_status_t status, uint8_t *payload, size_t payload_size)
 Initializes response with payload but no options. More...
 
static void unicoap_response_init_string (unicoap_message_t *response, unicoap_status_t status, const char *payload)
 Initializes response with payload from null-terminated UTF-8 string but no options. More...
 
static void unicoap_response_init_with_options (unicoap_message_t *response, unicoap_status_t status, uint8_t *payload, size_t payload_size, unicoap_options_t *options)
 Initializes response with byte payload and options. More...
 
static void unicoap_response_init_string_with_options (unicoap_message_t *response, unicoap_status_t status, const char *payload, unicoap_options_t *options)
 Initializes response with payload from null-terminated UTF-8 string and options. More...
 

Field Documentation

◆ code

uint8_t unicoap_message_t::code

CoAP message code.

A message code is divided into the class bits and detail bits, where C is a class bit and D is a detail bit. The class bits form a single-digit number, the detail bits represents a two-digit number. Hence, message codes are written as c.dd where c is the unsigned integer encoded in the three C bits and dd is the beforementioned two-digit number encoded in the five D bits.

Definition at line 131 of file message.h.

◆ method

unicoap_method_t unicoap_message_t::method

CoAP request method.

Precondition
Check if this is a request message before reading this property using unicoap_message_is_request.

Definition at line 144 of file message.h.

◆ options

unicoap_options_t* unicoap_message_t::options

Message options.

Key-value entries akin to HTTP headers

See also
Options

Definition at line 83 of file message.h.

◆ payload

uint8_t* unicoap_message_t::payload

Message payload.

Access via unicoap_message_payload_get and unicoap_message_payload_set.

Definition at line 98 of file message.h.

◆ payload_chunks

iolist_t* unicoap_message_t::payload_chunks

Noncontiguous payload.

Use one of these APIs:

Definition at line 117 of file message.h.

◆ payload_representation

unicoap_payload_representation_t unicoap_message_t::payload_representation

A value indicating how the payload is represented.

If the payload is noncontiguous, the unicoap_message_t::payload_chunks property must be accessed. Otherwise, only unicoap_message_t::payload must be read and written to.

Definition at line 169 of file message.h.

◆ payload_size

size_t unicoap_message_t::payload_size

Size of message payload.

Number of bytes in unicoap_message_t::payload. Access via unicoap_message_payload_get_size.

Definition at line 106 of file message.h.

◆ signal

unicoap_signal_t unicoap_message_t::signal

CoAP signal.

Check if this is a signaling message before reading this property using unicoap_message_is_signal.

Definition at line 160 of file message.h.

◆ status

unicoap_status_t unicoap_message_t::status

CoAP response status.

Precondition
Check if this is a response message before reading this property using unicoap_message_is_response.

Definition at line 152 of file message.h.


The documentation for this struct was generated from the following file: