1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

nanocoap: Add coap_opt_add_opaque

This option complements the existing coap_opt_add_{uint,string} and even
more special-purpose functions; its implementation is trivial given the
existing static _add_opt_pkt function.

The method is useful when working with ETags (ETag, If-Match options).
This commit is contained in:
chrysn 2019-04-12 10:47:53 +02:00
parent 364499f212
commit a51460984b
2 changed files with 22 additions and 0 deletions

View File

@ -656,6 +656,23 @@ size_t coap_put_block1_ok(uint8_t *pkt_pos, coap_block1_t *block1, uint16_t last
*/
ssize_t coap_opt_add_string(coap_pkt_t *pkt, uint16_t optnum, const char *string, char separator);
/**
* @brief Encode the given buffer as an opaque data option into pkt
*
* @post pkt.payload advanced to first byte after option(s)
* @post pkt.payload_len reduced by option(s) length
*
* @param[in,out] pkt pkt referencing target buffer
* @param[in] optnum option number to use
* @param[in] val pointer to the value to be set
* @param[in] val_len length of val
*
* @return number of bytes written to buffer
* @return <0 on error
* @return -ENOSPC if no available options
*/
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val, size_t val_len);
/**
* @brief Encode the given uint option into pkt
*

View File

@ -802,6 +802,11 @@ ssize_t coap_opt_add_string(coap_pkt_t *pkt, uint16_t optnum, const char *string
return write_len;
}
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, uint8_t *val, size_t val_len)
{
return _add_opt_pkt(pkt, optnum, val, val_len);
}
ssize_t coap_opt_add_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t value)
{
uint32_t tmp = value;