net/nanocoap: add function to retrieve opaque option
This commit is contained in:
parent
741d5437a7
commit
39eddce078
@ -573,6 +573,23 @@ static inline ssize_t coap_get_uri_query(const coap_pkt_t *pkt, uint8_t *target)
|
||||
*/
|
||||
ssize_t coap_opt_get_next(const coap_pkt_t *pkt, coap_optpos_t *opt,
|
||||
uint8_t **value, bool init_opt);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the value for an option as an opaque array of bytes
|
||||
*
|
||||
* Retrieves the location and length of the option value of any type. Useful for
|
||||
* an opaque option, which essentially is an array of bytes. If more than one
|
||||
* option for a given option number, retrieves the first option. To retrieve
|
||||
* subsequent options, see coap_opt_get_next().
|
||||
*
|
||||
* @param[in] pkt packet to read from
|
||||
* @param[in] opt_num option number to retrieve
|
||||
* @param[out] value start of the option value
|
||||
*
|
||||
* @return length of option; 0 if the option exists but is empty
|
||||
* @return -ENOENT if option not found
|
||||
*/
|
||||
ssize_t coap_opt_get_opaque(coap_pkt_t *pkt, unsigned opt_num, uint8_t **value);
|
||||
/**@}*/
|
||||
|
||||
|
||||
|
||||
@ -205,6 +205,20 @@ static uint8_t *_parse_option(const coap_pkt_t *pkt,
|
||||
return pkt_pos;
|
||||
}
|
||||
|
||||
ssize_t coap_opt_get_opaque(coap_pkt_t *pkt, unsigned opt_num, uint8_t **value)
|
||||
{
|
||||
uint8_t *start = coap_find_option(pkt, opt_num);
|
||||
if (!start) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
uint16_t delta;
|
||||
int len;
|
||||
|
||||
*value = _parse_option(pkt, start, &delta, &len);
|
||||
return len;
|
||||
}
|
||||
|
||||
int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target)
|
||||
{
|
||||
assert(target);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user