Create and serialize CoAP messages. More...
Create and serialize CoAP messages.
unicoap_message_t is the central container type for CoAP messages. To see how to access CoAP options, see Options. You may also look at the guide to using CoAP messages
You can access the CoAP code through different views, including as ast unicoap_message_t::method, unicoap_message_t::status, or unicoap_message_t::signal number.
Modules | |
Options | |
Access options from a CoAP message. | |
Parsing and Serialization | |
Tools for parsing PDUs and serializing messages and options. | |
Files | |
file | constants.h |
Constants used in CoAP such as option numbers and message codes. | |
Data Structures | |
struct | unicoap_message_t |
Generic CoAP message. More... | |
struct | unicoap_message_properties_t |
Properties of a CoAP message. More... | |
CoAP PDUs | |
enum | unicoap_protocol_version_t { UNICOAP_COAP_VERSION_1 = 1 } |
CoAP version number. More... | |
#define | UNICOAP_PAYLOAD_MARKER (0xFF) |
Marks the boundary between header and payload. | |
#define | UNICOAP_ETAG_LENGTH_MAX (8) |
Maximum length of the ETag option in bytes. | |
#define | UNICOAP_TOKEN_LENGTH_FIXED_WIDTH 4 |
Numbers of bits needed to represent token length. More... | |
RFC 7252 message types | |
enum | unicoap_rfc7252_message_type_t { UNICOAP_TYPE_CON = 0 , UNICOAP_TYPE_NON = 1 , UNICOAP_TYPE_ACK = 2 , UNICOAP_TYPE_RST = 3 } |
RFC 7252 message type. More... | |
#define | UNICOAP_RFC7252_MESSAGE_TYPE_FIXED_WIDTH 3 |
Number of bits needed to represent unicoap_rfc7252_message_type_t. | |
Message codes | |
enum | unicoap_code_class_t { UNICOAP_CODE_CLASS_REQUEST = 0 , UNICOAP_CODE_CLASS_RESPONSE_SUCCESS = 2 , UNICOAP_CODE_CLASS_RESPONSE_CLIENT_FAILURE = 4 , UNICOAP_CODE_CLASS_RESPONSE_SERVER_FAILURE = 5 , UNICOAP_CODE_CLASS_SIGNAL = 7 } |
Message code class. More... | |
enum | unicoap_method_t { UNICOAP_METHOD_GET = 1 , UNICOAP_METHOD_POST = 2 , UNICOAP_METHOD_PUT = 3 , UNICOAP_METHOD_DELETE = 4 , UNICOAP_METHOD_FETCH = 5 , UNICOAP_METHOD_PATCH = 6 , UNICOAP_METHOD_IPATCH = 7 } |
CoAP request method codes (0.xx range) More... | |
enum | unicoap_signal_t { UNICOAP_SIGNAL_CAPABILITIES_SETTINGS = 1 , UNICOAP_SIGNAL_PING = 2 , UNICOAP_SIGNAL_PONG = 3 , UNICOAP_SIGNAL_RELEASE = 4 , UNICOAP_SIGNAL_ABORT = 5 } |
CoAP Signal Message Codes (7.xx range) More... | |
enum | unicoap_status_t { UNICOAP_STATUS_CREATED = UNICOAP_CODE(RESPONSE_SUCCESS, 1) , UNICOAP_STATUS_DELETED = UNICOAP_CODE(RESPONSE_SUCCESS, 2) , UNICOAP_STATUS_VALID = UNICOAP_CODE(RESPONSE_SUCCESS, 3) , UNICOAP_STATUS_CHANGED = UNICOAP_CODE(RESPONSE_SUCCESS, 4) , UNICOAP_STATUS_CONTENT = UNICOAP_CODE(RESPONSE_SUCCESS, 5) , UNICOAP_STATUS_CONTINUE = UNICOAP_CODE(RESPONSE_SUCCESS, 31) , UNICOAP_STATUS_BAD_REQUEST = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 0) , UNICOAP_STATUS_UNAUTHORIZED = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 1) , UNICOAP_STATUS_BAD_OPTION = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 2) , UNICOAP_STATUS_FORBIDDEN = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 3) , UNICOAP_STATUS_PATH_NOT_FOUND = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 4) , UNICOAP_STATUS_METHOD_NOT_ALLOWED = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 5) , UNICOAP_STATUS_NOT_ACCEPTABLE = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 6) , UNICOAP_STATUS_REQUEST_ENTITY_INCOMPLETE = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 8) , UNICOAP_STATUS_CONFLICT = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 9) , UNICOAP_STATUS_PRECONDITION_FAILED = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 12) , UNICOAP_STATUS_REQUEST_ENTITY_TOO_LARGE = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 13) , UNICOAP_STATUS_UNSUPPORTED_CONTENT_FORMAT = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 15) , UNICOAP_STATUS_UNPROCESSABLE_ENTITY = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 22) , UNICOAP_STATUS_TOO_MANY_REQUESTS = UNICOAP_CODE(RESPONSE_CLIENT_FAILURE, 29) , UNICOAP_STATUS_INTERNAL_SERVER_ERROR = UNICOAP_CODE(RESPONSE_SERVER_FAILURE, 0) , UNICOAP_STATUS_NOT_IMPLEMENTED = UNICOAP_CODE(RESPONSE_SERVER_FAILURE, 1) , UNICOAP_STATUS_BAD_GATEWAY = UNICOAP_CODE(RESPONSE_SERVER_FAILURE, 2) , UNICOAP_STATUS_SERVICE_UNAVAILABLE = UNICOAP_CODE(RESPONSE_SERVER_FAILURE, 3) , UNICOAP_STATUS_GATEWAY_TIMEOUT = UNICOAP_CODE(RESPONSE_SERVER_FAILURE, 4) , UNICOAP_STATUS_PROXYING_NOT_SUPPORTED = UNICOAP_CODE(RESPONSE_SERVER_FAILURE, 5) } |
CoAP response status codes. More... | |
#define | UNICOAP_CODE_EMPTY (0) |
Code for an empty CoAP message. | |
CoAP message | |
enum | unicoap_payload_representation_t { UNICOAP_PAYLOAD_CONTIGUOUS = 0 , UNICOAP_PAYLOAD_NONCONTIGUOUS = 1 } |
A type indicating how a message's payload is represented. More... | |
const char * | unicoap_string_from_rfc7252_type (unicoap_rfc7252_message_type_t type) |
Returns a null-terminated label for the CoAP over UDP/DTLS message type. More... | |
static uint8_t * | unicoap_message_t::unicoap_message_payload_get (unicoap_message_t *message) |
Retrieves contiguous message payload, if available. More... | |
static void | unicoap_message_t::unicoap_message_payload_set (unicoap_message_t *message, uint8_t *payload, size_t size) |
Assigns the given message a contiguous payload. More... | |
static iolist_t * | unicoap_message_t::unicoap_message_payload_get_chunks (unicoap_message_t *message) |
Retrieves noncontiguous message payload, if available. More... | |
static void | unicoap_message_t::unicoap_message_payload_set_chunks (unicoap_message_t *message, iolist_t *chunks) |
Assigns the given message a noncontiguous payload. More... | |
void | unicoap_message_t::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_t::unicoap_message_payload_get_size (const unicoap_message_t *message) |
Retrieves payload size, regardless of payload representation. More... | |
bool | unicoap_message_t::unicoap_message_payload_is_empty (const unicoap_message_t *message) |
Determines whether message has any payload. More... | |
ssize_t | unicoap_message_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_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_t::unicoap_message_options_data (const unicoap_message_t *message) |
Retrieves options storage buffer. More... | |
static size_t | unicoap_message_t::unicoap_message_options_size (const unicoap_message_t *message) |
Retrieves total size of options in buffer. More... | |
CoAP code | |
static uint8_t | unicoap_code_class (uint8_t code) |
Reads the code class number encoded in the given code. More... | |
static uint8_t | unicoap_code_detail (uint8_t code) |
Reads the code detail number encoded in the given code. More... | |
int | unicoap_print_code (uint8_t code, char *string) |
Prints a c.dd class-detail string into the given buffer. More... | |
const char * | unicoap_string_from_code (uint8_t code) |
Returns label for given CoAP message code. More... | |
const char * | unicoap_string_from_code_class (uint8_t code) |
Returns label for given CoAP message code class. More... | |
Message initializers | |
static unicoap_message_t | unicoap_message_alloc_empty (uint8_t code) |
Creates message with no payload and no options. More... | |
static unicoap_message_t | unicoap_message_alloc (uint8_t code, uint8_t *payload, size_t payload_size) |
Creates message with no payload and no options. More... | |
static unicoap_message_t | unicoap_message_alloc_string (uint8_t code, const char *payload) |
Creates message with payload from null-terminated but no options. More... | |
static unicoap_message_t | unicoap_message_alloc_with_options (uint8_t code, uint8_t *payload, size_t payload_size, unicoap_options_t *options) |
Creates message with byte payload and options. More... | |
static unicoap_message_t | unicoap_message_alloc_string_with_options (uint8_t code, const char *payload, unicoap_options_t *options) |
Creates message with payload from null-terminated UTF-8 string and options. More... | |
static void | unicoap_message_t::unicoap_message_init_empty (unicoap_message_t *message, uint8_t code) |
Initializes message with no payload and no options. More... | |
static void | unicoap_message_t::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_t::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_t::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_t::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 bool | unicoap_message_is_signal (uint8_t code) |
Determines if the given message's code is a a signaling code. More... | |
const char * | unicoap_string_from_signal (unicoap_signal_t signal) |
Returns label for given CoAP signal code. More... | |
static unicoap_signal_t | unicoap_message_t::unicoap_message_get_signal (const unicoap_message_t *message) |
Retrieves signal code from given signal message. More... | |
static void | unicoap_message_t::unicoap_message_set_signal (unicoap_message_t *message, unicoap_signal_t signal) |
Sets signal code of given signal message. More... | |
Request messages | |
static bool | unicoap_message_is_request (uint8_t code) |
Determines if the the given message's code is a a request code. More... | |
const char * | unicoap_string_from_method (unicoap_method_t method) |
Obtains label for given request method. More... | |
static unicoap_message_t | unicoap_request_alloc_empty (unicoap_method_t method) |
Creates request with no payload and no options. More... | |
static unicoap_message_t | unicoap_request_alloc (unicoap_method_t method, uint8_t *payload, size_t payload_size) |
Creates request with no payload and no options. More... | |
static unicoap_message_t | unicoap_request_alloc_string (unicoap_method_t method, const char *payload) |
Creates request with payload from null-terminated UTF-8 string but no options. More... | |
static unicoap_message_t | unicoap_request_alloc_with_options (unicoap_method_t method, uint8_t *payload, size_t payload_size, unicoap_options_t *options) |
Creates request with byte payload and options. More... | |
static unicoap_message_t | unicoap_request_alloc_string_with_options (unicoap_method_t method, const char *payload, unicoap_options_t *options) |
Creates request with payload from null-terminated UTF-8 string and options. More... | |
static unicoap_method_t | unicoap_message_t::unicoap_request_get_method (const unicoap_message_t *request) |
Obtains request method from the given message's code. More... | |
static void | unicoap_message_t::unicoap_request_set_method (unicoap_message_t *request, unicoap_method_t method) |
Sets request method. More... | |
static void | unicoap_message_t::unicoap_request_init_empty (unicoap_message_t *request, unicoap_method_t method) |
Initializes request with no payload and no options. More... | |
static void | unicoap_message_t::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_message_t::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_message_t::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_message_t::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 | |
bool | unicoap_message_is_response (uint8_t code) |
Determines if the the given message's code is a a response code. More... | |
const char * | unicoap_string_from_status (unicoap_status_t status) |
Generates short descriptive label from CoAP status code. More... | |
static unicoap_message_t | unicoap_response_alloc_empty (unicoap_status_t status) |
Creates response with no payload and no options. More... | |
static unicoap_message_t | unicoap_response_alloc (unicoap_status_t status, uint8_t *payload, size_t payload_size) |
Creates response with no payload and no options. More... | |
static unicoap_message_t | unicoap_response_alloc_string (unicoap_status_t status, const char *payload) |
Creates response with payload from null-terminated UTF-8 string but no options. More... | |
static unicoap_message_t | unicoap_response_alloc_with_options (unicoap_status_t status, uint8_t *payload, size_t payload_size, unicoap_options_t *options) |
Creates response with string byte and options. More... | |
static unicoap_message_t | unicoap_response_alloc_string_with_options (unicoap_status_t status, const char *payload, unicoap_options_t *options) |
Creates response with payload from null-terminated UTF-8 string and options. More... | |
static unicoap_status_t | unicoap_message_t::unicoap_response_get_status (const unicoap_message_t *response) |
Obtains response status from the given message's code. More... | |
static void | unicoap_message_t::unicoap_response_set_status (unicoap_message_t *response, unicoap_status_t status) |
Sets response status. More... | |
static void | unicoap_message_t::unicoap_response_init_empty (unicoap_message_t *response, unicoap_status_t status) |
Initializes response with no payload and no options. More... | |
static void | unicoap_message_t::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_message_t::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_message_t::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_message_t::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... | |
#define UNICOAP_TOKEN_LENGTH_FIXED_WIDTH 4 |
Numbers of bits needed to represent token length.
Corresponds to TKL field width. As per RFC 7252, token lengths greater than 8 bytes must not be used. Hence, no more than 4 bits are needed, which is why TKL fields never occupy more than 4 bits.
Use this constant to define bitfields containing a token length member.
Definition at line 67 of file constants.h.
enum unicoap_code_class_t |
Message code class.
Corresponds to the upper three bits of a message code
Definition at line 121 of file constants.h.
enum unicoap_method_t |
CoAP request method codes (0.xx
range)
Definition at line 141 of file constants.h.
CoAP version number.
Enumerator | |
---|---|
UNICOAP_COAP_VERSION_1 | Identifier for CoAP version 1 (RFC 7252) |
Definition at line 41 of file constants.h.
RFC 7252 message type.
Enumerator | |
---|---|
UNICOAP_TYPE_CON | A confirmable message. |
UNICOAP_TYPE_NON | A non-confirmable message. |
UNICOAP_TYPE_ACK | An acknowledgement message. |
UNICOAP_TYPE_RST | An reset message. |
Definition at line 83 of file constants.h.
enum unicoap_signal_t |
CoAP Signal Message Codes (7.xx
range)
Each of these signaling messages has their own option number space.
Enumerator | |
---|---|
UNICOAP_SIGNAL_CAPABILITIES_SETTINGS | Capabilities and settings message (CSM)
|
UNICOAP_SIGNAL_PING | Ping message.
|
UNICOAP_SIGNAL_PONG | Pong message.
|
UNICOAP_SIGNAL_RELEASE | Release message.
|
UNICOAP_SIGNAL_ABORT | Abort message.
|
Definition at line 177 of file constants.h.
enum unicoap_status_t |
CoAP response status codes.
Enumerator | |
---|---|
UNICOAP_STATUS_CREATED | 2.01 Create
|
UNICOAP_STATUS_DELETED | 2.02 Deleted
|
UNICOAP_STATUS_VALID | 2.03 Valid
|
UNICOAP_STATUS_CHANGED | 2.04 Changed
|
UNICOAP_STATUS_CONTENT | 2.05 Content
|
UNICOAP_STATUS_CONTINUE | 2.31 Continue
|
UNICOAP_STATUS_BAD_REQUEST | 4.00 Bad Request
|
UNICOAP_STATUS_UNAUTHORIZED | 4.01 Unauthorized
|
UNICOAP_STATUS_BAD_OPTION | 4.02 Bad Option
|
UNICOAP_STATUS_FORBIDDEN | 4.03 Forbidden
|
UNICOAP_STATUS_PATH_NOT_FOUND | 4.04 Not Found
|
UNICOAP_STATUS_METHOD_NOT_ALLOWED | 4.05 Method Not Allowed
|
UNICOAP_STATUS_NOT_ACCEPTABLE | 4.06 Not Acceptable
|
UNICOAP_STATUS_REQUEST_ENTITY_INCOMPLETE | 4.08 Request Entity Incomplete
|
UNICOAP_STATUS_CONFLICT | 4.09 Conflict
|
UNICOAP_STATUS_PRECONDITION_FAILED | 4.12 Precondition Failed
|
UNICOAP_STATUS_REQUEST_ENTITY_TOO_LARGE | 4.13 Request Entity Too Large |
UNICOAP_STATUS_UNSUPPORTED_CONTENT_FORMAT | 4.15 Unsupported Content Format
|
UNICOAP_STATUS_UNPROCESSABLE_ENTITY | Unprocessable Entity.
|
UNICOAP_STATUS_TOO_MANY_REQUESTS | 4.29 Too Many Requests
|
UNICOAP_STATUS_INTERNAL_SERVER_ERROR | 5.00 Internal Server Error
|
UNICOAP_STATUS_NOT_IMPLEMENTED | 5.01 Not Implemented
|
UNICOAP_STATUS_BAD_GATEWAY | 5.02 Bad Gateway
|
UNICOAP_STATUS_SERVICE_UNAVAILABLE | 5.03 Service Unavailable
|
UNICOAP_STATUS_GATEWAY_TIMEOUT | 5.04 Gateway Timeout
|
UNICOAP_STATUS_PROXYING_NOT_SUPPORTED | 5.05 Proxying Not Supported
|
Definition at line 215 of file constants.h.
|
inlinestatic |
Reads the code class number encoded in the given code.
A message code is divided into the three class bits and five detail bits. The class bits form a single-digit number, the detail bits represents a two-digit number. Hence, message codes are written as c.dd
. In the following listing, C
is a class bit and D
is a detail bit. The C
bits represent the class c
, and the D
bits form the detail number d
.
code | Message code |
|
inlinestatic |
Reads the code detail number encoded in the given code.
A message code is divided into the three class bits and five detail bits. The class bits form a single-digit number, the detail bits represents a two-digit number. Hence, message codes are written as c.dd
. In the following listing, C
is a class bit and D
is a detail bit. The C
bits represent the class c
, and the D
bits form the detail number d
.
code | Message code |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Creates message with payload from null-terminated UTF-8 string and options.
code | Message code | |
[in] | payload | Payload string (nullable), must be null-terminated |
[in] | options | Message options, must be pre-allocated and pre-initialized |
options
is allocated
|
inlinestatic |
Creates message with byte payload and options.
code | Message code | |
[in] | payload | Payload bytes (nullable) |
payload_size | Payload size | |
[in] | options | Message options, must be pre-allocated and pre-initialized |
options
is allocated
|
inline |
Retrieves signal code from given signal message.
[in] | message | CoAP signal |
|
inline |
|
inline |
|
inline |
|
inline |
Initializes message with payload from null-terminated UTF-8 string and options.
[in,out] | message | Pre-allocated message structure |
code | Message code | |
[in] | payload | Payload string (nullable), must be null-terminated |
[in] | options | Message options, must be pre-allocated and pre-initialized |
message
is allocated options
is allocated
|
inline |
Initializes message with byte payload and options.
[in,out] | message | Pre-allocated message structure |
code | Message code | |
[in] | payload | Payload bytes (nullable) |
payload_size | Payload size | |
[in] | options | Message options, must be pre-allocated and pre-initialized |
message
is allocated options
is allocated
|
inlinestatic |
bool unicoap_message_is_response | ( | uint8_t | code | ) |
Determines if the the given message's code is a a response code.
This function internally reads the code class encoded in the code's upper three bits.
code | Message code |
|
inlinestatic |
|
inline |
|
inline |
void unicoap_message_payload_append_chunk | ( | unicoap_message_t * | message, |
iolist_t * | chunk | ||
) |
Appends a payload chunk to a message.
message | Message | |
[in] | chunk | Payload chunk |
ssize_t unicoap_message_payload_copy | ( | const unicoap_message_t * | message, |
uint8_t * | buffer, | ||
size_t | capacity | ||
) |
Copies payload into given buffer.
message | Message whose payload to copy | |
[in,out] | buffer | Destination payload buffer |
capacity | Capacity of buffer in bytes |
-ENOBUFS
if given buffer is too smallYou can call this method regardless of whether payload is stored contiguously or noncontiguously.
|
inline |
Retrieves contiguous message payload, if available.
message | Message to retrieve payload buffer from |
|
inline |
Retrieves noncontiguous message payload, if available.
message | Message to retrieve payload vector from |
|
inline |
Retrieves payload size, regardless of payload representation.
message | Message whose payload size to compute (if noncontiguous payload) or retrieve (contiguous payload). |
bool unicoap_message_payload_is_empty | ( | const unicoap_message_t * | message | ) |
Determines whether message has any payload.
message | Message with payload in question |
The given message may still have a buffer or iolist vector associated, yet this function returns false
if the buffer or vector is empty.
ssize_t unicoap_message_payload_make_contiguous | ( | unicoap_message_t * | message, |
uint8_t * | buffer, | ||
size_t | capacity | ||
) |
Copies noncontiguous payload into contiguous storage buffer.
[in,out] | message | Message whose payload to make contiguous |
[in,out] | buffer | Destination payload buffer |
capacity | Capacity of buffer in bytes |
-ENOBUFS
if given buffer is too small
|
inline |
|
inline |
|
inline |
int unicoap_print_code | ( | uint8_t | code, |
char * | string | ||
) |
Prints a c.dd
class-detail string into the given buffer.
string
must have a capacity of at least 4 characters code | Message code | |
[out] | string | Buffer to write string into |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Creates request with payload from null-terminated UTF-8 string and options.
method | Request method | |
[in] | payload | Payload string (nullable), must be null-terminated |
[in] | options | Message options, must be pre-allocated and pre-initialized |
options
is allocated
|
inlinestatic |
Creates request with byte payload and options.
method | Request method | |
[in] | payload | Payload bytes (nullable) |
payload_size | Payload size | |
[in] | options | Message options, must be pre-allocated and pre-initialized |
options
is allocated
|
inline |
Obtains request method from the given message's code.
[in] | request | Request message, pre-initialized |
|
inline |
|
inline |
|
inline |
|
inline |
Initializes request with payload from null-terminated UTF-8 string and options.
[in,out] | request | Pre-allocated request structure |
method | Request method | |
[in] | payload | Payload string (nullable), must be null-terminated |
[in] | options | Message options, must be pre-allocated and pre-initialized |
request
is allocated options
is allocated
|
inline |
Initializes request with byte payload and options.
[in,out] | request | Pre-allocated request structure |
method | Request method | |
[in] | payload | Payload bytes (nullable) |
payload_size | Payload size | |
[in] | options | Message options, must be pre-allocated and pre-initialized |
request
is allocated options
is allocated
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Creates response with payload from null-terminated UTF-8 string and options.
status | Response status | |
[in] | payload | Payload string (nullable), must be null-terminated |
[in] | options | Message options, must be pre-allocated and pre-initialized |
options
is allocated
|
inlinestatic |
Creates response with string byte and options.
status | Response status | |
[in] | payload | Payload bytes (nullable) |
payload_size | Payload size | |
[in] | options | Message options, must be pre-allocated and pre-initialized |
options
is allocated
|
inline |
Obtains response status from the given message's code.
[in] | response | Response message, pre-initialized |
|
inline |
|
inline |
|
inline |
Initializes response with payload from null-terminated UTF-8 string but no options.
[in,out] | response | Pre-allocated response structure |
status | Response status | |
[in] | payload | Payload string (nullable), must be null-terminated |
response
is allocated
|
inline |
Initializes response with payload from null-terminated UTF-8 string and options.
[in,out] | response | Pre-allocated response structure |
status | Response status | |
[in] | payload | Payload string (nullable), must be null-terminated |
[in] | options | Message options, must be pre-allocated and pre-initialized |
response
is allocated options
is allocated
|
inline |
Initializes response with byte payload and options.
[in,out] | response | Pre-allocated response structure |
status | Response status | |
[in] | payload | Payload bytes (nullable) |
payload_size | Payload size | |
[in] | options | Message options, must be pre-allocated and pre-initialized |
response
is allocated options
is allocated
|
inline |
const char* unicoap_string_from_code | ( | uint8_t | code | ) |
Returns label for given CoAP message code.
code | CoAP message code |
"POST"
, "Abort"
, or "Bad Request"
"?"
if code is unknown const char* unicoap_string_from_code_class | ( | uint8_t | code | ) |
Returns label for given CoAP message code class.
code | CoAP message code |
"REQ"
, "RES"
, "SIGNAL"
, or "EMPTY"
"?"
if code class is unknown const char* unicoap_string_from_method | ( | unicoap_method_t | method | ) |
Obtains label for given request method.
Returns "GET"
, "PUT"
, "POST"
, ...
method | Request method to return label for |
const char* unicoap_string_from_rfc7252_type | ( | unicoap_rfc7252_message_type_t | type | ) |
Returns a null-terminated label for the CoAP over UDP/DTLS message type.
type | CoAP over UDP/DTLS message. |
NULL
<tt>"NON"</tt> | A non-confirmable message |
<tt>"CON"</tt> | A confirmable message |
<tt>"ACK"</tt> | An acknowledgement message |
<tt>"RST"</tt> | A reset message |
<tt>"?"</tt> | Unknown message type |
const char* unicoap_string_from_signal | ( | unicoap_signal_t | signal | ) |
Returns label for given CoAP signal code.
signal | CoAP signal code |
"Ping"
, "Abort"
, or "CSM"
"?"
if code is unknown const char* unicoap_string_from_status | ( | unicoap_status_t | status | ) |
Generates short descriptive label from CoAP status code.
status | CoAP status code |
"?"
if status code is unknown