1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

net/nanocoap: add generic uint block option

This commit is contained in:
Ken Bannister 2019-02-24 06:06:30 -05:00
parent 8de39d80b7
commit 233dd31e17
2 changed files with 22 additions and 0 deletions

View File

@ -1038,6 +1038,20 @@ static inline size_t coap_opt_put_block2(uint8_t *buf, uint16_t lastonum,
return coap_opt_put_block(buf, lastonum, slicer, more, COAP_OPT_BLOCK2);
}
/**
* @brief Encode the given uint option into buffer
*
* @param[out] buf buffer to write to
* @param[in] lastonum number of previous option (for delta calculation),
* or 0 for first option
* @param[in] onum number of option
* @param[in] value value to encode
*
* @returns amount of bytes written to @p buf
*/
size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
uint32_t value);
/**
* @brief Insert block option into buffer from block struct
*

View File

@ -810,6 +810,14 @@ size_t coap_opt_put_string(uint8_t *buf, uint16_t lastonum, uint16_t optnum,
return bufpos - buf;
}
size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
uint32_t value)
{
unsigned uint_len = _encode_uint(&value);
return coap_put_option(buf, lastonum, onum, (uint8_t *)&value, uint_len);
}
/* Common functionality for addition of an option */
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val,
size_t val_len)