Merge pull request #13893 from cgundogan/pr/nanocoap-get-opt-uint

nanocoap: export coap_opt_get_uint()
This commit is contained in:
Ken Bannister 2020-04-18 10:00:27 -04:00 committed by GitHub
commit cac350901f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -446,6 +446,20 @@ static inline void coap_hdr_set_type(coap_hdr_t *hdr, unsigned type)
*/
unsigned coap_get_content_type(coap_pkt_t *pkt);
/**
* @brief Get a uint32 option value
*
* @param[in] pkt packet to read from
* @param[in] optnum absolute option number
* @param[out] value the parsed option value
*
* @return 0 if the option was found and the value was parsed correctly
* @return -ENOENT if the option was not found in @p pkt
* @return -ENOSPC if option length is greater than 4 octets
* @return -EBADMSG if option value is invalid
*/
int coap_opt_get_uint(const coap_pkt_t *pkt, uint16_t optnum, uint32_t *value);
/**
* @brief Read a full option as null terminated string into the target buffer
*

View File

@ -42,7 +42,6 @@
/** @} */
static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end);
int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target);
static uint32_t _decode_uint(uint8_t *pkt_pos, unsigned nbytes);
static size_t _encode_uint(uint32_t *val);
@ -135,7 +134,7 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
}
#ifdef MODULE_GCOAP
if (coap_get_option_uint(pkt, COAP_OPT_OBSERVE, &pkt->observe_value) != 0) {
if (coap_opt_get_uint(pkt, COAP_OPT_OBSERVE, &pkt->observe_value) != 0) {
pkt->observe_value = UINT32_MAX;
}
#endif
@ -224,7 +223,7 @@ ssize_t coap_opt_get_opaque(const coap_pkt_t *pkt, unsigned opt_num, uint8_t **v
return len;
}
int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target)
int coap_opt_get_uint(const coap_pkt_t *pkt, uint16_t opt_num, uint32_t *target)
{
assert(target);
@ -246,7 +245,7 @@ int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target)
return -EBADMSG;
}
}
return -1;
return -ENOENT;
}
uint8_t *coap_iterate_option(const coap_pkt_t *pkt, uint8_t **optpos,