mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
json: Add helper for quoted numbers
The JSON specification technically disallows maps with numeric keys, so we'll want to slowly migrate away from using them. This helper extracts the numeric value from a quoted number, which is a legal representation of the same in JSON.
This commit is contained in:
@@ -88,6 +88,19 @@ bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num)
|
||||
{
|
||||
jsmntok_t temp;
|
||||
if (tok->type != JSMN_STRING)
|
||||
return false;
|
||||
|
||||
temp = *tok;
|
||||
temp.start += 1;
|
||||
temp.end -= 1;
|
||||
|
||||
return json_to_u64(buffer, &temp, num);
|
||||
}
|
||||
|
||||
bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num)
|
||||
{
|
||||
uint64_t u64;
|
||||
|
||||
Reference in New Issue
Block a user