common/json.c: Implement json_to_u32.

This commit is contained in:
ZmnSCPxj jxPCSnmZ
2020-01-15 16:04:03 +08:00
committed by Christian Decker
parent fb7c006187
commit 44e8256338
2 changed files with 19 additions and 0 deletions

View File

@@ -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;