Browse Source

common/json.c: Implement `json_to_u32`.

travis-debug
ZmnSCPxj jxPCSnmZ 5 years ago
committed by Christian Decker
parent
commit
44e8256338
  1. 15
      common/json.c
  2. 4
      common/json.h

15
common/json.c

@ -105,6 +105,21 @@ bool json_to_u16(const char *buffer, const jsmntok_t *tok,
return true;
}
bool json_to_u32(const char *buffer, const jsmntok_t *tok,
uint32_t *num)
{
uint64_t u64;
if (!json_to_u64(buffer, tok, &u64))
return false;
*num = u64;
/* Just in case it doesn't fit. */
if (*num != u64)
return false;
return true;
}
bool json_to_int(const char *buffer, const jsmntok_t *tok, int *num)
{
char *end;

4
common/json.h

@ -37,6 +37,10 @@ bool json_to_number(const char *buffer, const jsmntok_t *tok,
bool json_to_u64(const char *buffer, const jsmntok_t *tok,
uint64_t *num);
/* Extract number from this (may be a string, or a number literal) */
bool json_to_u32(const char *buffer, const jsmntok_t *tok,
uint32_t *num);
/* Extract number from this (may be a string, or a number literal) */
bool json_to_u16(const char *buffer, const jsmntok_t *tok,
uint16_t *num);

Loading…
Cancel
Save