Loading...
Searching...
No Matches
coap_builder_t Struct Reference

Structure to hold the state for building a CoAP message. More...

Detailed Description

Structure to hold the state for building a CoAP message.

Note
The idea is that this structure supports sequential appendages to the message to iteratively build a CoAP message. The pos member points to the current writing position. Before appending data, users must check if that operation would overflow, that is, if advancing pos by the amount of data to append would exceed the buffers capacity given by size.
Warning
Do not access the pos member for checking the message size, but use coap_builder_msg_size to do so with error checks!
Note
All functions trying to append to the message may set the size member to 0 to indicate an overflow. This way subsequent appends will reliably fail even if they are smaller and would fit. A caller may decide to ignore the return value of all append calls except for the last without risking overflows, risking to create a corrupted message (with skipped parts), or missing to detect errors: They only need to either check the return value of the last function appending to the builder or - more conveniently - use coap_builder_msg_size to get the return value of the response handler.

Definition at line 454 of file nanocoap.h.

#include <nanocoap.h>

Data Fields

uint8_t * buf
 Buffer to build the message into.
 
uint16_t pos
 Position of the next byte to write within buf
 
uint16_t size
 Size of buf in bytes.
 
uint16_t last_opt_num
 Number of the last option added (for delta-encoding)
 

Field Documentation

◆ buf

uint8_t* coap_builder_t::buf

Buffer to build the message into.

Definition at line 455 of file nanocoap.h.

◆ last_opt_num

uint16_t coap_builder_t::last_opt_num

Number of the last option added (for delta-encoding)

Definition at line 458 of file nanocoap.h.

◆ pos

uint16_t coap_builder_t::pos

Position of the next byte to write within buf

Definition at line 456 of file nanocoap.h.

◆ size

uint16_t coap_builder_t::size

Size of buf in bytes.

Definition at line 457 of file nanocoap.h.


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