Skip to content

Commit c02872f

Browse files
committed
net/nanocoap: add generic uint block option
1 parent ca69b47 commit c02872f

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

sys/include/net/nanocoap.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,20 @@ static inline size_t coap_opt_put_block2(uint8_t *buf, uint16_t lastonum,
935935
return coap_opt_put_block(buf, lastonum, slicer, more, COAP_OPT_BLOCK2);
936936
}
937937

938+
/**
939+
* @brief Encode the given uint option into buffer
940+
*
941+
* @param[out] buf buffer to write to
942+
* @param[in] lastonum number of previous option (for delta calculation),
943+
* or 0 for first option
944+
* @param[in] onum number of option
945+
* @param[in] value value to encode
946+
*
947+
* @returns amount of bytes written to @p buf
948+
*/
949+
size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
950+
uint32_t value);
951+
938952
/**
939953
* @brief Insert block option into buffer from block struct
940954
*

sys/net/application_layer/nanocoap/nanocoap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,15 @@ size_t coap_opt_put_string(uint8_t *buf, uint16_t lastonum, uint16_t optnum,
725725
return bufpos - buf;
726726
}
727727

728+
size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
729+
uint32_t value)
730+
{
731+
uint32_t tmp = value;
732+
unsigned tmp_len = _encode_uint(&tmp);
733+
734+
return coap_put_option(buf, lastonum, onum, (uint8_t *)&tmp, tmp_len);
735+
}
736+
728737
/* Common functionality for addition of an option */
729738
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, uint8_t *val,
730739
size_t val_len)

0 commit comments

Comments
 (0)