Go to the documentation of this file.
43 #include "upb/port_def.inc"
53 const char* line_begin;
71 return str.size == strlen(lit) && memcmp(
str.data, lit,
str.size) == 0;
77 "google.protobuf.NullValue") == 0;
89 (
int)(
d->ptr -
d->line_begin),
msg);
97 (
int)(
d->ptr -
d->line_begin));
105 while (
d->ptr !=
d->end) {
109 d->line_begin =
d->ptr;
124 if (
d->ptr ==
d->end || *
d->ptr !=
ch)
return false;
130 size_t avail =
d->end -
d->ptr;
131 size_t len = strlen(lit);
132 if (avail <
len || memcmp(
d->ptr, lit,
len) != 0) {
201 if (--
d->depth < 0) {
208 bool is_first =
d->is_first;
211 if (*
d->ptr == end_ch)
return false;
249 const char*
start =
d->ptr;
251 while (
d->ptr <
d->end) {
252 if (*
d->ptr <
'0' || *
d->ptr >
'9') {
268 const char*
start =
d->ptr;
273 if (*
d->ptr ==
'-')
d->ptr++;
283 if (
d->ptr ==
d->end)
goto parse;
287 if (
d->ptr ==
d->end)
goto parse;
289 if (*
d->ptr ==
'e' || *
d->ptr ==
'E') {
291 if (
d->ptr ==
d->end) {
294 if (*
d->ptr ==
'+' || *
d->ptr ==
'-') {
307 assert(
end ==
d->ptr);
318 if (val > DBL_MAX || val < -DBL_MAX) {
355 if (
d->end -
d->ptr < 4) {
360 while (
d->ptr <
end) {
362 if (
ch >=
'0' &&
ch <=
'9') {
364 }
else if (
ch >=
'a' &&
ch <=
'f') {
366 }
else if (
ch >=
'A' &&
ch <=
'F') {
380 if (cp >= 0xd800 && cp <= 0xdbff) {
386 if (low < 0xdc00 || low > 0xdfff) {
389 cp = (high & 0x3ff) << 10;
392 }
else if (cp >= 0xdc00 && cp <= 0xdfff) {
400 }
else if (cp <= 0x07FF) {
401 out[0] = ((cp >> 6) & 0x1F) | 0xC0;
402 out[1] = ((cp >> 0) & 0x3F) | 0x80;
404 }
else if (cp <= 0xFFFF) {
405 out[0] = ((cp >> 12) & 0x0F) | 0xE0;
406 out[1] = ((cp >> 6) & 0x3F) | 0x80;
407 out[2] = ((cp >> 0) & 0x3F) | 0x80;
409 }
else if (cp < 0x10FFFF) {
410 out[0] = ((cp >> 18) & 0x07) | 0xF0;
411 out[1] = ((cp >> 12) & 0x3f) | 0x80;
412 out[2] = ((cp >> 6) & 0x3f) | 0x80;
413 out[3] = ((cp >> 0) & 0x3f) | 0x80;
421 size_t oldsize = *buf_end - *
buf;
435 char* buf_end = NULL;
439 if (*
d->ptr++ !=
'"') {
443 while (
d->ptr <
d->end) {
446 if (
end == buf_end) {
459 if (
d->ptr ==
d->end)
goto eof;
460 if (*
d->ptr ==
'u') {
462 if (buf_end -
end < 4) {
472 if ((
unsigned char)*
d->ptr < 0x20) {
524 const signed char table[256] = {
525 -1, -1, -1, -1, -1, -1, -1,
526 -1, -1, -1, -1, -1, -1, -1,
527 -1, -1, -1, -1, -1, -1, -1,
528 -1, -1, -1, -1, -1, -1, -1,
529 -1, -1, -1, -1, -1, -1, -1,
530 -1, -1, -1, -1, -1, -1, -1,
531 -1, 62 , -1, 62 , -1, 63 , 52 ,
532 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
533 60 , 61 , -1, -1, -1, -1, -1,
534 -1, -1, 0 , 1 , 2 , 3 , 4 ,
535 5 , 6 , 07 , 8 , 9 , 10 , 11 ,
536 12 , 13 , 14 , 15 , 16 , 17 , 18 ,
537 19 , 20 , 21 , 22 , 23 , 24 , 25 ,
538 -1, -1, -1, -1, 63 , -1, 26 ,
539 27 , 28 , 29 , 30 , 31 , 32 , 33 ,
540 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
541 41 , 42 , 43 , 44 , 45 , 46 , 47 ,
542 48 , 49 , 50 , 51 , -1, -1, -1,
543 -1, -1, -1, -1, -1, -1, -1,
544 -1, -1, -1, -1, -1, -1, -1,
545 -1, -1, -1, -1, -1, -1, -1,
546 -1, -1, -1, -1, -1, -1, -1,
547 -1, -1, -1, -1, -1, -1, -1,
548 -1, -1, -1, -1, -1, -1, -1,
549 -1, -1, -1, -1, -1, -1, -1,
550 -1, -1, -1, -1, -1, -1, -1,
551 -1, -1, -1, -1, -1, -1, -1,
552 -1, -1, -1, -1, -1, -1, -1,
553 -1, -1, -1, -1, -1, -1, -1,
554 -1, -1, -1, -1, -1, -1, -1,
555 -1, -1, -1, -1, -1, -1, -1,
556 -1, -1, -1, -1, -1, -1, -1,
557 -1, -1, -1, -1, -1, -1, -1,
558 -1, -1, -1, -1, -1, -1, -1,
559 -1, -1, -1, -1, -1, -1, -1,
560 -1, -1, -1, -1, -1, -1, -1,
583 out[1] = (val >> 8) & 0xff;
598 char*
out = (
char*)
str.data;
599 const char*
ptr =
str.data;
601 const char* end4 =
ptr + (
str.size & -4);
622 out[1] = (val >> 8) & 0xff;
643 unsigned ch = *
ptr -
'0';
672 *val = neg ? -u64 : u64;
680 jsondec_err(
d,
"Non-number characters in quoted integer");
689 jsondec_err(
d,
"Non-number characters in quoted integer");
703 if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) {
708 jsondec_errf(
d,
"JSON number was not integral (%f != %" PRId64
")", dbl,
740 if (dbl > 18446744073709549568.0 || dbl < 0) {
745 jsondec_errf(
d,
"JSON number was not integral (%f != %" PRIu64
")", dbl,
939 if (
name.size >= 2 &&
name.data[0] ==
'[' &&
945 d,
"Extension %s extends message %s, but was seen in message %s",
974 preserved =
d->debug_field;
990 d->debug_field = preserved;
1030 const char*
after) {
1032 const char*
p = *
ptr;
1033 const char*
end =
p + digits;
1034 size_t after_len =
after ? strlen(
after) : 0;
1039 (after_len && memcmp(
end,
after, after_len) != 0)) {
1051 const char*
p = *
ptr;
1053 if (
p !=
end && *
p ==
'.') {
1055 int digits = (
int)(nano_end -
p - 1);
1056 int exp_lg10 = 9 - digits;
1060 while (exp_lg10--) nanos *= 10;
1074 const uint32_t adjust = carry ? 12 : 0;
1075 const uint32_t y_adj =
y + year_base - carry;
1076 const uint32_t month_days = ((m_adj + adjust) * 62719 + 769) / 2048;
1077 const uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400;
1078 return y_adj * 365 + leap_days + month_days + (
d - 1) - 2472632;
1090 const char*
ptr =
str.data;
1093 if (
str.size < 20)
goto malformed;
1115 if (
ptr ==
end)
goto malformed;
1122 if ((
end -
ptr) != 5)
goto malformed;
1125 ofs_min = ((ofs_hour * 60) + ofs_min) * 60;
1126 seconds.int64_val += (neg ? ofs_min : -ofs_min);
1129 if (
ptr !=
end)
goto malformed;
1136 if (
seconds.int64_val < -62135596800) {
1154 const char*
ptr =
str.data;
1189 value.msg_val = value_msg;
1209 value.msg_val = value_msg;
1282 ret.size += (*
ptr >=
'A' && *
ptr <=
'Z');
1292 if (
ch >=
'A' &&
ch <=
'Z') {
1295 }
else if (
ch ==
'_') {
1311 const char*
ptr =
str.data;
1316 const char* elem_end = memchr(
ptr,
',',
end -
ptr);
1340 jsondec_err(
d,
"Key for well-known type must be 'value'");
1363 jsondec_err(
d,
"Type url must have at least one '/' and non-empty host");
1382 const char* pre_type_data = NULL;
1383 const char* pre_type_end = NULL;
1390 const char*
start =
d->ptr;
1395 if (pre_type_data) {
1396 pre_type_end =
start;
1397 while (*pre_type_end !=
',') pre_type_end--;
1400 if (!pre_type_data) pre_type_data =
start;
1406 jsondec_err(
d,
"Any object didn't contain a '@type' field");
1411 if (pre_type_data) {
1412 size_t len = pre_type_end - pre_type_data + 1;
1414 const char* saved_ptr =
d->ptr;
1415 const char* saved_end =
d->end;
1491 if (
size == 0)
return true;
1501 d.line_begin =
d.ptr;
1502 d.debug_field = NULL;
@ kUpb_WellKnown_StringValue
uint32_t upb_FieldDef_Number(const upb_FieldDef *f)
std::chrono::duration< std::int_fast64_t > seconds
static upb_MessageValue jsondec_strfield(jsondec *d, const upb_FieldDef *f)
static upb_MessageValue jsondec_double(jsondec *d, const upb_FieldDef *f)
static void jsondec_wellknownvalue(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
const upb_EnumValueDef * upb_EnumDef_FindValueByNameWithSize(const upb_EnumDef *def, const char *name, size_t len)
static int64_t jsondec_strtoint64(jsondec *d, upb_StringView str)
UPB_INLINE void * upb_Arena_Realloc(upb_Arena *a, void *ptr, size_t oldsize, size_t size)
static void jsondec_parselit(jsondec *d, const char *lit)
static void jsondec_entrysep(jsondec *d)
const upb_MiniTable * upb_MessageDef_MiniTable(const upb_MessageDef *m)
static upb_MessageValue jsondec_uint(jsondec *d, const upb_FieldDef *f)
#define UPB_STRINGVIEW_ARGS(view)
static char jsondec_escape(jsondec *d)
#define UPB_UNREACHABLE()
static void jsondec_objstart(jsondec *d)
static upb_MessageValue jsondec_bool(jsondec *d, const upb_FieldDef *f)
static const char * jsondec_buftouint64(jsondec *d, const char *ptr, const char *end, uint64_t *val)
#define UPB_PRINTF(str, first_vararg)
static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s)
static void jsondec_timestamp(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
const upb_OneofDef * upb_FieldDef_RealContainingOneof(const upb_FieldDef *f)
static bool jsondec_isvalue(const upb_FieldDef *f)
static bool jsondec_seqnext(jsondec *d, char end_ch)
grpc_core::ScopedArenaPtr arena
static upb_StringView jsondec_mask(jsondec *d, const char *buf, const char *end)
upb_Message * upb_Message_New(const upb_MessageDef *m, upb_Arena *a)
@ kUpb_WellKnown_FloatValue
static size_t jsondec_base64(jsondec *d, upb_StringView str)
static void jsondec_struct(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
const upb_FieldDef * upb_MessageDef_FindByJsonNameWithSize(const upb_MessageDef *m, const char *name, size_t len)
static upb_StringView jsondec_string(jsondec *d)
static void jsondec_fieldmask(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
UPB_INLINE bool upb_MessageDef_IsMapEntry(const upb_MessageDef *m)
upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef *m)
static size_t jsondec_unicode(jsondec *d, char *out)
bool upb_FieldDef_IsMap(const upb_FieldDef *f)
static bool jsondec_arrnext(jsondec *d)
@ kUpb_WellKnown_BytesValue
@ kUpb_WellKnown_Unspecified
@ kUpb_WellKnown_Timestamp
UPB_INLINE void * upb_Arena_Malloc(upb_Arena *a, size_t size)
void upb_Status_VAppendErrorFormat(upb_Status *status, const char *fmt, va_list args)
static void jsondec_arrend(jsondec *d)
static void jsondec_listvalue(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static int jsondec_rawpeek(jsondec *d)
unsigned __int64 uint64_t
const char * upb_EnumDef_FullName(const upb_EnumDef *e)
@ kUpb_WellKnown_UInt32Value
void upb_Status_SetErrorFormat(upb_Status *status, const char *fmt,...)
static const upb_MessageDef * jsondec_typeurl(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static void jsondec_field(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static bool jsondec_streql(upb_StringView str, const char *lit)
@ kUpb_WellKnown_BoolValue
#define UPB_STRINGVIEW_FORMAT
static double jsondec_number(jsondec *d)
static void jsondec_array(jsondec *d, upb_Message *msg, const upb_FieldDef *f)
static const char *const mon[12]
const upb_Message * msg_val
bool upb_Array_Append(upb_Array *arr, upb_MessageValue val, upb_Arena *arena)
static bool jsondec_objnext(jsondec *d)
upb_CType upb_FieldDef_CType(const upb_FieldDef *f)
static void jsondec_skipval(jsondec *d)
static void jsondec_any(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static void jsondec_objend(jsondec *d)
static void jsondec_wellknown(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
const upb_MessageDef * upb_FieldDef_MessageSubDef(const upb_FieldDef *f)
const upb_EnumDef * upb_FieldDef_EnumSubDef(const upb_FieldDef *f)
const upb_FieldDef * upb_DefPool_FindExtensionByNameWithSize(const upb_DefPool *s, const char *name, size_t size)
static int jsondec_peek(jsondec *d)
IntAfterTypedTestSuiteP after
static void jsondec_push(jsondec *d)
bool upb_Map_Set(upb_Map *map, upb_MessageValue key, upb_MessageValue val, upb_Arena *arena)
static void jsondec_null(jsondec *d)
static UPB_NORETURN void jsondec_errf(jsondec *d, const char *fmt,...)
static void jsondec_object(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static void jsondec_wrapper(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static void jsondec_skipws(jsondec *d)
const upb_DefPool * symtab
static void jsondec_map(jsondec *d, upb_Message *msg, const upb_FieldDef *f)
GTEST_API_ const char * fmt
static void jsondec_resize(jsondec *d, char **buf, char **end, char **buf_end)
char * upb_Encode(const void *msg, const upb_MiniTable *l, int options, upb_Arena *arena, size_t *size)
const upb_MessageDef * upb_FieldDef_ContainingType(const upb_FieldDef *f)
@ kUpb_WellKnown_UInt64Value
static void jsondec_anyfield(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
@ kUpb_WellKnown_Duration
static int jsondec_nanos(jsondec *d, const char **ptr, const char *end)
const upb_FieldDef * debug_field
static uint64_t jsondec_strtouint64(jsondec *d, upb_StringView str)
static const char * jsondec_buftoint64(jsondec *d, const char *ptr, const char *end, int64_t *val)
static void jsondec_true(jsondec *d)
@ upb_JsonDecode_IgnoreUnknown
static void jsondec_tomsg(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
upb_MutableMessageValue upb_Message_Mutable(upb_Message *msg, const upb_FieldDef *f, upb_Arena *a)
bool upb_FieldDef_IsRepeated(const upb_FieldDef *f)
const upb_MessageDef * upb_DefPool_FindMessageByNameWithSize(const upb_DefPool *s, const char *sym, size_t len)
static void jsondec_false(jsondec *d)
const upb_FieldDef * upb_Message_WhichOneof(const upb_Message *msg, const upb_OneofDef *o)
UniquePtr< SSL_SESSION > ret
bool upb_JsonDecode(const char *buf, size_t size, upb_Message *msg, const upb_MessageDef *m, const upb_DefPool *symtab, int options, upb_Arena *arena, upb_Status *status)
static char * jsondec_partialbase64(jsondec *d, const char *ptr, const char *end, char *out)
int jsondec_epochdays(int y, int m, int d)
std::array< int64_t, Size > values
static upb_MessageValue jsondec_enum(jsondec *d, const upb_FieldDef *f)
static void parse(const char *s)
const char * upb_MessageDef_FullName(const upb_MessageDef *m)
@ kUpb_WellKnown_ListValue
@ kUpb_WellKnown_Int64Value
static void jsondec_duration(jsondec *d, upb_Message *msg, const upb_MessageDef *m)
static int jsondec_tsdigits(jsondec *d, const char **ptr, size_t digits, const char *after)
@ kUpb_WellKnown_DoubleValue
@ kUpb_WellKnown_Int32Value
static uint32_t jsondec_codepoint(jsondec *d)
bool upb_FieldDef_IsSubMessage(const upb_FieldDef *f)
const upb_OneofDef * upb_FieldDef_ContainingOneof(const upb_FieldDef *f)
static void jsondec_wsch(jsondec *d, char ch)
static upb_MessageValue jsondec_msg(jsondec *d, const upb_FieldDef *f)
static void jsondec_arrstart(jsondec *d)
static unsigned int jsondec_base64_tablelookup(const char ch)
static UPB_NORETURN void jsondec_err(jsondec *d, const char *msg)
static bool jsondec_tryparsech(jsondec *d, char ch)
bool upb_Message_Set(upb_Message *msg, const upb_FieldDef *f, upb_MessageValue val, upb_Arena *a)
@ kUpb_WellKnown_FieldMask
static upb_MessageValue jsondec_value(jsondec *d, const upb_FieldDef *f)
const upb_FieldDef * upb_MessageDef_FindFieldByNumber(const upb_MessageDef *m, uint32_t i)
int32_t upb_EnumValueDef_Number(const upb_EnumValueDef *ev)
static upb_MessageValue jsondec_int(jsondec *d, const upb_FieldDef *f)
const char * upb_FieldDef_FullName(const upb_FieldDef *f)
#define UPB_LONGJMP(buf, val)
static bool jsondec_tryskipdigits(jsondec *d)
static bool jsondec_isnullvalue(const upb_FieldDef *f)
static void jsondec_skipdigits(jsondec *d)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:25