|
|
@ -208,25 +208,27 @@ static size_t fmt_bool(bool val, char* buf, size_t length) { |
|
|
|
return n; |
|
|
|
return n; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static size_t fmt_int32(long long val, char* buf, size_t length) { |
|
|
|
static size_t fmt_int64_as_number(long long val, char* buf, size_t length) { |
|
|
|
size_t n = _upb_snprintf(buf, length, "%lld", val); |
|
|
|
size_t n = _upb_snprintf(buf, length, "%lld", val); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
return n; |
|
|
|
return n; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static size_t fmt_uint32(unsigned long long val, char* buf, size_t length) { |
|
|
|
static size_t fmt_uint64_as_number( |
|
|
|
|
|
|
|
unsigned long long val, char* buf, size_t length) { |
|
|
|
size_t n = _upb_snprintf(buf, length, "%llu", val); |
|
|
|
size_t n = _upb_snprintf(buf, length, "%llu", val); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
return n; |
|
|
|
return n; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static size_t fmt_int64(long long val, char* buf, size_t length) { |
|
|
|
static size_t fmt_int64_as_string(long long val, char* buf, size_t length) { |
|
|
|
size_t n = _upb_snprintf(buf, length, "\"%lld\"", val); |
|
|
|
size_t n = _upb_snprintf(buf, length, "\"%lld\"", val); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
return n; |
|
|
|
return n; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) { |
|
|
|
static size_t fmt_uint64_as_string( |
|
|
|
|
|
|
|
unsigned long long val, char* buf, size_t length) { |
|
|
|
size_t n = _upb_snprintf(buf, length, "\"%llu\"", val); |
|
|
|
size_t n = _upb_snprintf(buf, length, "\"%llu\"", val); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
CHKLENGTH(n > 0 && n < length); |
|
|
|
return n; |
|
|
|
return n; |
|
|
@ -287,17 +289,17 @@ static bool putkey(void *closure, const void *handler_data) { |
|
|
|
TYPE_HANDLERS(double, fmt_double) |
|
|
|
TYPE_HANDLERS(double, fmt_double) |
|
|
|
TYPE_HANDLERS(float, fmt_float) |
|
|
|
TYPE_HANDLERS(float, fmt_float) |
|
|
|
TYPE_HANDLERS(bool, fmt_bool) |
|
|
|
TYPE_HANDLERS(bool, fmt_bool) |
|
|
|
TYPE_HANDLERS(int32_t, fmt_int32) |
|
|
|
TYPE_HANDLERS(int32_t, fmt_int64_as_number) |
|
|
|
TYPE_HANDLERS(uint32_t, fmt_int32) |
|
|
|
TYPE_HANDLERS(uint32_t, fmt_int64_as_number) |
|
|
|
TYPE_HANDLERS(int64_t, fmt_int64) |
|
|
|
TYPE_HANDLERS(int64_t, fmt_int64_as_string) |
|
|
|
TYPE_HANDLERS(uint64_t, fmt_uint64) |
|
|
|
TYPE_HANDLERS(uint64_t, fmt_uint64_as_string) |
|
|
|
|
|
|
|
|
|
|
|
/* double and float are not allowed to be map keys. */ |
|
|
|
/* double and float are not allowed to be map keys. */ |
|
|
|
TYPE_HANDLERS_MAPKEY(bool, fmt_bool) |
|
|
|
TYPE_HANDLERS_MAPKEY(bool, fmt_bool) |
|
|
|
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int32) |
|
|
|
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number) |
|
|
|
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int32) |
|
|
|
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number) |
|
|
|
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int32) |
|
|
|
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number) |
|
|
|
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint32) |
|
|
|
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number) |
|
|
|
|
|
|
|
|
|
|
|
#undef TYPE_HANDLERS |
|
|
|
#undef TYPE_HANDLERS |
|
|
|
#undef TYPE_HANDLERS_MAPKEY |
|
|
|
#undef TYPE_HANDLERS_MAPKEY |
|
|
|