message.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2024-2025 Carl Seifert
3  * SPDX-FileCopyrightText: 2024-2025 TU Dresden
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <stddef.h>
12 #include <string.h>
13 
14 #include "iolist.h"
15 
16 #include "net/unicoap/constants.h"
17 #include "net/unicoap/options.h"
18 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* MARK: - CoAP message */
42 typedef enum {
47 
53 
72 typedef struct {
81 
85  union {
89  struct {
95  uint8_t* payload;
96 
103  size_t payload_size;
104  };
105 
115  };
116 
117  union {
128  uint8_t code;
129 
130  /* Note:
131  * Method, status, and signal are guaranteed to have the same size as uint8_t,
132  * see static_asserts in definitions.h
133  */
134 
142 
150 
158  };
159 
168 
178 static inline uint8_t* unicoap_message_payload_get(unicoap_message_t* message)
179 {
181  return message->payload;
182 }
183 
192 static inline void unicoap_message_payload_set(unicoap_message_t* message, uint8_t* payload,
193  size_t size)
194 {
196  message->payload = payload;
197  message->payload_size = size;
198 }
199 
210 {
212  return message->payload_chunks;
213 }
214 
222 static inline void unicoap_message_payload_set_chunks(unicoap_message_t* message, iolist_t* chunks)
223 {
225  message->payload_chunks = chunks;
226 }
227 
237 
248 static inline size_t unicoap_message_payload_get_size(const unicoap_message_t* message)
249 {
251  iolist_size(message->payload_chunks) :
252  message->payload_size;
253 }
254 
265 
278 ssize_t unicoap_message_payload_copy(const unicoap_message_t* message, uint8_t* buffer,
279  size_t capacity);
280 
292  size_t capacity);
293 
297 typedef struct {
299  uint8_t* token;
300 
303 
309  bool is_registration : 1;
310 
316  bool is_notification : 1;
317 
319  struct {
322 
324  uint16_t id;
325  } rfc7252;
326 
329 
343 
350 static inline uint8_t* unicoap_message_options_data(const unicoap_message_t* message)
351 {
352  return message->options ? message->options->entries->data : NULL;
353 }
354 
361 static inline size_t unicoap_message_options_size(const unicoap_message_t* message)
362 {
363  return message->options ? message->options->storage_size : 0;
364 }
367 /* MARK: - CoAP code */
390 static inline uint8_t unicoap_code_class(uint8_t code)
391 {
392  return code >> 5;
393 }
394 
413 static inline uint8_t unicoap_code_detail(uint8_t code)
414 {
415  return code & 0x1f;
416 }
417 
425 int unicoap_print_code(uint8_t code, char* string);
426 
435 const char* unicoap_string_from_code(uint8_t code);
436 
445 const char* unicoap_string_from_code_class(uint8_t code);
448 /* MARK: - Message initializers */
460 static inline void unicoap_message_init_empty(unicoap_message_t* message, uint8_t code)
461 {
462  message->code = code;
463  message->options = NULL;
464  message->payload = NULL;
465  message->payload_size = 0;
466 }
467 
474 {
475  return (unicoap_message_t){ .code = code };
476 }
477 
487 static inline void unicoap_message_init(unicoap_message_t* message, uint8_t code, uint8_t* payload,
488  size_t payload_size)
489 {
490  message->code = code;
491  message->options = NULL;
492  message->payload = payload;
493  message->payload_size = payload_size;
494 }
495 
503 static inline unicoap_message_t unicoap_message_alloc(uint8_t code, uint8_t* payload,
504  size_t payload_size)
505 {
506  return (unicoap_message_t){ .code = code, .payload = payload, .payload_size = payload_size };
507 }
508 
518 static inline void unicoap_message_init_string(unicoap_message_t* message, uint8_t code,
519  const char* payload)
520 {
521  message->code = code;
522  message->options = NULL;
523  message->payload = (uint8_t*)payload;
524  message->payload_size = payload ? strlen(payload) : 0;
525 }
526 
533 static inline unicoap_message_t unicoap_message_alloc_string(uint8_t code, const char* payload)
534 {
535  return (unicoap_message_t){ .code = code,
536  .payload = (uint8_t*)payload,
537  .payload_size = payload ? strlen(payload) : 0 };
538 }
539 
552 static inline void unicoap_message_init_with_options(unicoap_message_t* message, uint8_t code,
553  uint8_t* payload, size_t payload_size,
554  unicoap_options_t* options)
555 {
556  message->code = code;
557  message->options = options;
558  message->payload = payload;
559  message->payload_size = payload_size;
560 }
561 
571 static inline unicoap_message_t unicoap_message_alloc_with_options(uint8_t code, uint8_t* payload,
572  size_t payload_size,
573  unicoap_options_t* options)
574 {
575  return (unicoap_message_t){
576  .code = code, .options = options, .payload = payload, .payload_size = payload_size
577  };
578 }
579 
591 static inline
593  const char* payload,
594  unicoap_options_t* options)
595 {
596  unicoap_message_init_with_options(message, code, (uint8_t*)payload,
597  payload ? strlen(payload) : 0, options);
598 }
599 
608 static inline
610  const char* payload,
611  unicoap_options_t* options)
612 {
613  return (unicoap_message_t){ .code = code,
614  .options = options,
615  .payload = (uint8_t*)payload,
616  .payload_size = payload ? strlen(payload) : 0 };
617 }
620 /* MARK: - Signaling messages */
634 static inline bool unicoap_message_is_signal(uint8_t code)
635 {
637 }
638 
647 {
648  return message->signal;
649 }
650 
659 {
660  message->signal = signal;
661 }
662 
674 /* MARK: - Request messages */
687 static inline bool unicoap_message_is_request(uint8_t code)
688 {
690 }
691 
700 {
701  return request->method;
702 }
703 
713 {
714  request->method = method;
715 }
716 
726 
736 {
737  unicoap_message_init_empty(request, (uint8_t)method);
738 }
739 
746 {
747  return unicoap_message_alloc_empty((uint8_t)method);
748 }
749 
760 static inline void unicoap_request_init(unicoap_message_t* request, unicoap_method_t method,
761  uint8_t* payload, size_t payload_size)
762 {
763  unicoap_message_init(request, (uint8_t)method, payload, payload_size);
764 }
765 
773 static inline unicoap_message_t unicoap_request_alloc(unicoap_method_t method, uint8_t* payload,
774  size_t payload_size)
775 {
776  return unicoap_message_alloc((uint8_t)method, payload, payload_size);
777 }
778 
789  const char* payload)
790 {
791  unicoap_message_init_string(request, (uint8_t)method, payload);
792 }
793 
801  const char* payload)
802 {
803  return unicoap_message_alloc_string((uint8_t)method, payload);
804 }
805 
819  unicoap_method_t method,
820  uint8_t* payload, size_t payload_size,
821  unicoap_options_t* options)
822 {
823  unicoap_message_init_with_options(request, (uint8_t)method, payload, payload_size, options);
824 }
825 
836  uint8_t* payload,
837  size_t payload_size,
838  unicoap_options_t* options)
839 {
840  return unicoap_message_alloc_with_options((uint8_t)method, payload, payload_size, options);
841 }
842 
855  unicoap_method_t method,
856  const char* payload,
857  unicoap_options_t* options)
858 {
859  unicoap_message_init_string_with_options(request, (uint8_t)method, payload, options);
860 }
861 
870 static inline
872  const char* payload,
873  unicoap_options_t* options)
874 {
875  return unicoap_message_alloc_string_with_options((uint8_t)method, payload, options);
876 }
879 /* MARK: - Response messages */
893 bool unicoap_message_is_response(uint8_t code);
894 
903 {
904  return response->status;
905 }
906 
916 {
917  response->status = status;
918 }
919 
926 
936 {
937  unicoap_message_init_empty(response, (uint8_t)status);
938 }
939 
946 {
947  return unicoap_message_alloc_empty((uint8_t)status);
948 }
949 
960 static inline void unicoap_response_init(unicoap_message_t* response, unicoap_status_t status,
961  uint8_t* payload, size_t payload_size)
962 {
963  unicoap_message_init(response, (uint8_t)status, payload, payload_size);
964 }
965 
973 static inline unicoap_message_t unicoap_response_alloc(unicoap_status_t status, uint8_t* payload,
974  size_t payload_size)
975 {
976  return unicoap_message_alloc((uint8_t)status, payload, payload_size);
977 }
978 
988 static inline void unicoap_response_init_string(unicoap_message_t* response,
989  unicoap_status_t status, const char* payload)
990 {
991  unicoap_message_init_string(response, (uint8_t)status, payload);
992 }
993 
1001  const char* payload)
1002 {
1003  return unicoap_message_alloc_string((uint8_t)status, payload);
1004 }
1005 
1019  unicoap_status_t status,
1020  uint8_t* payload,
1021  size_t payload_size,
1022  unicoap_options_t* options)
1023 {
1024  unicoap_message_init_with_options(response, (uint8_t)status, payload, payload_size, options);
1025 }
1026 
1037  uint8_t* payload,
1038  size_t payload_size,
1039  unicoap_options_t* options)
1040 {
1041  return unicoap_message_alloc_with_options((uint8_t)status, payload, payload_size, options);
1042 }
1043 
1056  unicoap_status_t status,
1057  const char* payload,
1058  unicoap_options_t* options)
1059 {
1060  unicoap_message_init_string_with_options(response, (uint8_t)status, payload, options);
1061 }
1062 
1071 static inline
1073  const char* payload,
1074  unicoap_options_t* options)
1075 {
1076  return unicoap_message_alloc_string_with_options((uint8_t)status, payload, options);
1077 }
1081 /* MARK: - Parsing and Serialization ------------------------------------------------------- */
1086 /* MARK: - Parsing */
1106 typedef ssize_t (*unicoap_parser_t)(const uint8_t* pdu, size_t size, unicoap_message_t* message,
1107  unicoap_message_properties_t* properties);
1108 
1114 typedef struct {
1117 
1120 
1124 
1151 ssize_t unicoap_pdu_parse_options_and_payload(uint8_t* cursor, const uint8_t* end,
1152  unicoap_message_t* message);
1155 /* MARK: - Serializing */
1173 ssize_t unicoap_pdu_build_options_and_payload(uint8_t* cursor, size_t remaining_capacity,
1174  const unicoap_message_t* message);
1175 
1180 #define UNICOAP_PDU_IOLIST_COUNT (4)
1181 
1199 int unicoap_pdu_buildv_options_and_payload(uint8_t* header, size_t header_size,
1200  const unicoap_message_t* message,
1242 ssize_t unicoap_pdu_parse_rfc7252(uint8_t* pdu, size_t size, unicoap_message_t* message,
1243  unicoap_message_properties_t* properties);
1244 
1269 static inline ssize_t unicoap_pdu_parse_rfc7252_result(uint8_t* pdu, size_t size,
1270  unicoap_parser_result_t* parsed)
1271 {
1272  parsed->message.options = &parsed->options;
1273  return unicoap_pdu_parse_rfc7252(pdu, size, &parsed->message, &parsed->properties);
1274 }
1292 ssize_t unicoap_pdu_build_header_rfc7252(uint8_t* header, size_t capacity,
1293  const unicoap_message_t* message,
1294  const unicoap_message_properties_t* properties);
1295 
1308 static inline ssize_t unicoap_pdu_build_rfc7252(uint8_t* pdu, size_t capacity,
1309  const unicoap_message_t* message,
1310  const unicoap_message_properties_t* properties)
1311 {
1312  ssize_t res = 0;
1313 
1314  if ((res = unicoap_pdu_build_header_rfc7252(pdu, capacity, message, properties)) < 0) {
1315  return res;
1316  }
1317  return unicoap_pdu_build_options_and_payload(pdu + res, capacity - res, message) + res;
1318 }
1319 
1320 /* MARK: unicoap_driver_extension_point */
1321 
1338 static inline ssize_t unicoap_pdu_buildv_rfc7252(uint8_t* header, size_t header_capacity,
1339  const unicoap_message_t* message,
1340  const unicoap_message_properties_t* properties,
1342 {
1343  ssize_t res = 0;
1344 
1345  if ((res =
1346  unicoap_pdu_build_header_rfc7252(header, header_capacity, message, properties)) < 0) {
1347  return res;
1348  }
1349  return unicoap_pdu_buildv_options_and_payload(header, res, message, iolists);
1350 }
1351 
1354 /* MARK: unicoap_driver_extension_point */
1355 
1356 #ifdef __cplusplus
1357 }
1358 #endif
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:143
Constants used in CoAP such as option numbers and message codes.
static bool unicoap_message_is_request(uint8_t code)
Determines if the the given message's code is a a request code.
Definition: message.h:687
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.
const char * unicoap_string_from_code_class(uint8_t code)
Returns label for given CoAP message code class.
static void unicoap_request_set_method(unicoap_message_t *request, unicoap_method_t method)
Sets request method.
Definition: message.h:712
static void unicoap_message_payload_set(unicoap_message_t *message, uint8_t *payload, size_t size)
Assigns the given message a contiguous payload.
Definition: message.h:192
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.
Definition: message.h:835
static iolist_t * unicoap_message_payload_get_chunks(unicoap_message_t *message)
Retrieves noncontiguous message payload, if available.
Definition: message.h:209
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.
Definition: message.h:973
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.
Definition: message.h:552
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.
Definition: message.h:773
const char * unicoap_string_from_status(unicoap_status_t status)
Generates short descriptive label from CoAP status code.
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.
Definition: message.h:818
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.
Definition: message.h:609
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.
Definition: message.h:788
static uint8_t * unicoap_message_options_data(const unicoap_message_t *message)
Retrieves options storage buffer.
Definition: message.h:350
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.
Definition: message.h:871
static uint8_t * unicoap_message_payload_get(unicoap_message_t *message)
Retrieves contiguous message payload, if available.
Definition: message.h:178
static unicoap_message_t unicoap_response_alloc_empty(unicoap_status_t status)
Creates response with no payload and no options.
Definition: message.h:945
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.
Definition: message.h:503
static void unicoap_message_set_signal(unicoap_message_t *message, unicoap_signal_t signal)
Sets signal code of given signal message.
Definition: message.h:658
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.
Definition: message.h:1072
static void unicoap_response_init_empty(unicoap_message_t *response, unicoap_status_t status)
Initializes response with no payload and no options.
Definition: message.h:935
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.
Definition: message.h:592
ssize_t unicoap_message_payload_make_contiguous(unicoap_message_t *message, uint8_t *buffer, size_t capacity)
Copies noncontiguous payload into contiguous storage buffer.
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.
Definition: message.h:988
static unicoap_message_t unicoap_message_alloc_empty(uint8_t code)
Creates message with no payload and no options.
Definition: message.h:473
static uint8_t unicoap_code_detail(uint8_t code)
Reads the code detail number encoded in the given code.
Definition: message.h:413
#define UNICOAP_RFC7252_MESSAGE_TYPE_FIXED_WIDTH
Number of bits needed to represent unicoap_rfc7252_message_type_t.
Definition: constants.h:75
static unicoap_message_t unicoap_message_alloc_string(uint8_t code, const char *payload)
Creates message with payload from null-terminated but no options.
Definition: message.h:533
ssize_t unicoap_message_payload_copy(const unicoap_message_t *message, uint8_t *buffer, size_t capacity)
Copies payload into given buffer.
int unicoap_print_code(uint8_t code, char *string)
Prints a c.dd class-detail string into the given buffer.
static uint8_t unicoap_code_class(uint8_t code)
Reads the code class number encoded in the given code.
Definition: message.h:390
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.
Definition: message.h:854
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.
Definition: message.h:760
const char * unicoap_string_from_signal(unicoap_signal_t signal)
Returns label for given CoAP signal code.
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.
Definition: message.h:1018
const char * unicoap_string_from_method(unicoap_method_t method)
Obtains label for given request method.
static unicoap_status_t unicoap_response_get_status(const unicoap_message_t *response)
Obtains response status from the given message's code.
Definition: message.h:902
static size_t unicoap_message_payload_get_size(const unicoap_message_t *message)
Retrieves payload size, regardless of payload representation.
Definition: message.h:248
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.
Definition: message.h:1055
const char * unicoap_string_from_code(uint8_t code)
Returns label for given CoAP message code.
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.
Definition: message.h:1036
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.
Definition: message.h:960
static bool unicoap_message_is_signal(uint8_t code)
Determines if the given message's code is a a signaling code.
Definition: message.h:634
unicoap_payload_representation_t
A type indicating how a message's payload is represented.
Definition: message.h:42
static void unicoap_request_init_empty(unicoap_message_t *request, unicoap_method_t method)
Initializes request with no payload and no options.
Definition: message.h:735
bool unicoap_message_payload_is_empty(const unicoap_message_t *message)
Determines whether message has any payload.
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.
Definition: message.h:571
static unicoap_method_t unicoap_request_get_method(const unicoap_message_t *request)
Obtains request method from the given message's code.
Definition: message.h:699
unicoap_status_t
CoAP response status codes.
Definition: constants.h:212
static unicoap_message_t unicoap_request_alloc_empty(unicoap_method_t method)
Creates request with no payload and no options.
Definition: message.h:745
static void unicoap_message_init_empty(unicoap_message_t *message, uint8_t code)
Initializes message with no payload and no options.
Definition: message.h:460
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.
Definition: message.h:1000
unicoap_signal_t
CoAP Signal Message Codes (7.xx range)
Definition: constants.h:174
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.
Definition: message.h:800
static void unicoap_message_payload_set_chunks(unicoap_message_t *message, iolist_t *chunks)
Assigns the given message a noncontiguous payload.
Definition: message.h:222
unicoap_rfc7252_message_type_t
RFC 7252 message type.
Definition: constants.h:80
bool unicoap_message_is_response(uint8_t code)
Determines if the the given message's code is a a response code.
static void unicoap_response_set_status(unicoap_message_t *response, unicoap_status_t status)
Sets response status.
Definition: message.h:915
static unicoap_signal_t unicoap_message_get_signal(const unicoap_message_t *message)
Retrieves signal code from given signal message.
Definition: message.h:646
#define UNICOAP_TOKEN_LENGTH_FIXED_WIDTH
Numbers of bits needed to represent token length.
Definition: constants.h:64
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.
Definition: message.h:518
unicoap_method_t
CoAP request method codes (0.xx range)
Definition: constants.h:138
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.
Definition: message.h:487
static size_t unicoap_message_options_size(const unicoap_message_t *message)
Retrieves total size of options in buffer.
Definition: message.h:361
void unicoap_message_payload_append_chunk(unicoap_message_t *message, iolist_t *chunk)
Appends a payload chunk to a message.
@ UNICOAP_CODE_CLASS_SIGNAL
Signaling message.
Definition: constants.h:132
@ UNICOAP_CODE_CLASS_REQUEST
Message class for requests.
Definition: constants.h:120
@ UNICOAP_PAYLOAD_NONCONTIGUOUS
iolist_t payload vector
Definition: message.h:51
@ UNICOAP_PAYLOAD_CONTIGUOUS
Contiguous payload buffer.
Definition: message.h:46
ssize_t unicoap_pdu_build_options_and_payload(uint8_t *cursor, size_t remaining_capacity, const unicoap_message_t *message)
Populates the given buffer with options and payload.
ssize_t unicoap_pdu_parse_rfc7252(uint8_t *pdu, size_t size, unicoap_message_t *message, unicoap_message_properties_t *properties)
Parses RFC 7252 PDU.
ssize_t unicoap_pdu_parse_options_and_payload(uint8_t *cursor, const uint8_t *end, unicoap_message_t *message)
Parses PDU starting at options.
static ssize_t unicoap_pdu_build_rfc7252(uint8_t *pdu, size_t capacity, const unicoap_message_t *message, const unicoap_message_properties_t *properties)
Writes RFC 7252 PDU into buffer.
Definition: message.h:1308
static ssize_t unicoap_pdu_buildv_rfc7252(uint8_t *header, size_t header_capacity, const unicoap_message_t *message, const unicoap_message_properties_t *properties, iolist_t iolists[UNICOAP_PDU_IOLIST_COUNT])
Populates the given iolist with header according to RFC 7252, options, and payload.
Definition: message.h:1338
#define UNICOAP_PDU_IOLIST_COUNT
Number of iolists in the iolist buffer that must be passed to unicoap_pdu_buildv_options_and_payload.
Definition: message.h:1180
ssize_t unicoap_pdu_build_header_rfc7252(uint8_t *header, size_t capacity, const unicoap_message_t *message, const unicoap_message_properties_t *properties)
Writes RFC 7252 PDU header in the given buffer.
static ssize_t unicoap_pdu_parse_rfc7252_result(uint8_t *pdu, size_t size, unicoap_parser_result_t *parsed)
Helper method for manually parsing a PDU.
Definition: message.h:1269
ssize_t(* unicoap_parser_t)(const uint8_t *pdu, size_t size, unicoap_message_t *message, unicoap_message_properties_t *properties)
Common PDU parser.
Definition: message.h:1106
int unicoap_pdu_buildv_options_and_payload(uint8_t *header, size_t header_size, const unicoap_message_t *message, iolist_t iolists[UNICOAP_PDU_IOLIST_COUNT])
Populates the given iolist with header, options, payload separator and payload.
size_t iolist_size(const iolist_t *iolist)
Sum up number of bytes in iolist.
iolist scatter / gather IO
Options header.
iolist structure definition
Definition: iolist.h:35
Properties of a CoAP message.
Definition: message.h:297
bool is_registration
Determines if the corresponding message is considered an Observe registration.
Definition: message.h:309
uint16_t id
RFC 7252 message ID.
Definition: message.h:324
uint8_t * token
CoAP token used to correlate requests to responses.
Definition: message.h:299
uint8_t token_length
Length of unicoap_message_properties_t::token.
Definition: message.h:302
bool is_notification
Determines if the corresponding message is considered an Observe notification.
Definition: message.h:316
unicoap_rfc7252_message_type_t type
RFC 7252 message type.
Definition: message.h:321
Generic CoAP message.
Definition: message.h:72
unicoap_payload_representation_t payload_representation
A value indicating how the payload is represented.
Definition: message.h:166
unicoap_method_t method
CoAP request method.
Definition: message.h:141
size_t payload_size
Size of message payload.
Definition: message.h:103
unicoap_status_t status
CoAP response status.
Definition: message.h:149
uint8_t * payload
Message payload.
Definition: message.h:95
uint8_t code
CoAP message code.
Definition: message.h:128
unicoap_signal_t signal
CoAP signal.
Definition: message.h:157
unicoap_options_t * options
Message options.
Definition: message.h:80
iolist_t * payload_chunks
Noncontiguous payload.
Definition: message.h:114
uint8_t * data
Pointer into options storage where this option starts.
Definition: options.h:76
CoAP options container.
Definition: options.h:97
size_t storage_size
Current size of encoded options.
Definition: options.h:103
unicoap_option_entry_t entries[CONFIG_UNICOAP_OPTIONS_MAX]
Helper array used to encode and decode options into options storage.
Definition: options.h:118
Helper structure for parsing PDUs manually.
Definition: message.h:1114
unicoap_message_properties_t properties
Parsed message properties.
Definition: message.h:1122
unicoap_options_t options
Parsed options.
Definition: message.h:1119
unicoap_message_t message
Message.
Definition: message.h:1116