mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #11386 from chrysn-pull-requests/nanocoap-add-opaque
nanocoap: Support adding opaque (blob / buffer) data
This commit is contained in:
commit
a4b909dba4
@ -463,7 +463,7 @@ void coap_pkt_init(coap_pkt_t *pkt, uint8_t *buf, size_t len, size_t header_len)
|
|||||||
*
|
*
|
||||||
* @returns amount of bytes written to @p buf
|
* @returns amount of bytes written to @p buf
|
||||||
*/
|
*/
|
||||||
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *odata, size_t olen);
|
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const uint8_t *odata, size_t olen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Insert content type option into buffer
|
* @brief Insert content type option into buffer
|
||||||
@ -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);
|
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
|
* @brief Encode the given uint option into pkt
|
||||||
*
|
*
|
||||||
|
@ -566,7 +566,7 @@ static unsigned _put_delta_optlen(uint8_t *buf, unsigned offset, unsigned shift,
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *odata, size_t olen)
|
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const uint8_t *odata, size_t olen)
|
||||||
{
|
{
|
||||||
assert(lastonum <= onum);
|
assert(lastonum <= onum);
|
||||||
|
|
||||||
@ -728,7 +728,7 @@ size_t coap_opt_put_string(uint8_t *buf, uint16_t lastonum, uint16_t optnum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Common functionality for addition of an option */
|
/* Common functionality for addition of an option */
|
||||||
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, uint8_t *val,
|
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val,
|
||||||
size_t val_len)
|
size_t val_len)
|
||||||
{
|
{
|
||||||
if (pkt->options_len >= NANOCOAP_NOPTS_MAX) {
|
if (pkt->options_len >= NANOCOAP_NOPTS_MAX) {
|
||||||
@ -802,6 +802,11 @@ ssize_t coap_opt_add_string(coap_pkt_t *pkt, uint16_t optnum, const char *string
|
|||||||
return write_len;
|
return write_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const 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)
|
ssize_t coap_opt_add_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t value)
|
||||||
{
|
{
|
||||||
uint32_t tmp = value;
|
uint32_t tmp = value;
|
||||||
|
Loading…
Reference in New Issue
Block a user