Fix json encoding for wrappers, ListValue, Struct and Value. (#126)

* Fix json encoding for wrappers, ListValue, Struct and Value.

* Add well_known_type field in upb_msgdef to specify type of well known messages.

* Remove comma at end of enum definition.

* Group number wrappers

* Fix comments

* Refactoring to use is_wellknown_{msg/field}
pull/13171/head
Paul Yang 6 years ago committed by GitHub
parent 4271689953
commit 706ffdbc65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      tests/json/test.upbdefs.c
  2. 26
      tools/dump_cinit.lua
  3. 69
      upb/def.c
  4. 67
      upb/def.h
  5. 44
      upb/descriptor/descriptor.upbdefs.c
  6. 1
      upb/descriptor/reader.c
  7. 368
      upb/json/parser.c
  8. 256
      upb/json/parser.rl
  9. 198
      upb/json/printer.c
  10. 9
      upb/structdefs.int.h

@ -20,14 +20,14 @@ static upb_inttable reftables[92];
#endif #endif
static const upb_msgdef msgs[8] = { static const upb_msgdef msgs[8] = {
UPB_MSGDEF_INIT("upb.test.json.SubMessage", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[0]), false, UPB_SYNTAX_PROTO3, &reftables[0], &reftables[1]), UPB_MSGDEF_INIT("upb.test.json.SubMessage", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[0]), false, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[0], &reftables[1]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage", 73, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[2], 26, 24), UPB_STRTABLE_INIT(24, 31, UPB_CTYPE_PTR, 5, &strentries[4]), false, UPB_SYNTAX_PROTO3, &reftables[2], &reftables[3]), UPB_MSGDEF_INIT("upb.test.json.TestMessage", 73, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[2], 26, 24), UPB_STRTABLE_INIT(24, 31, UPB_CTYPE_PTR, 5, &strentries[4]), false, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[2], &reftables[3]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapBoolStringEntry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[28], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), true, UPB_SYNTAX_PROTO3, &reftables[4], &reftables[5]), UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapBoolStringEntry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[28], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), true, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[4], &reftables[5]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapInt32StringEntry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[40]), true, UPB_SYNTAX_PROTO3, &reftables[6], &reftables[7]), UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapInt32StringEntry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[40]), true, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[6], &reftables[7]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringBoolEntry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[34], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[44]), true, UPB_SYNTAX_PROTO3, &reftables[8], &reftables[9]), UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringBoolEntry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[34], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[44]), true, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[8], &reftables[9]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringInt32Entry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[37], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[48]), true, UPB_SYNTAX_PROTO3, &reftables[10], &reftables[11]), UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringInt32Entry", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[37], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[48]), true, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[10], &reftables[11]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringMsgEntry", 8, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[40], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[52]), true, UPB_SYNTAX_PROTO3, &reftables[12], &reftables[13]), UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringMsgEntry", 8, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[40], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[52]), true, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[12], &reftables[13]),
UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringStringEntry", 9, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[43], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[56]), true, UPB_SYNTAX_PROTO3, &reftables[14], &reftables[15]), UPB_MSGDEF_INIT("upb.test.json.TestMessage.MapStringStringEntry", 9, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[43], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[56]), true, UPB_SYNTAX_PROTO3, UPB_WELLKNOWN_UNSPECIFIED, &reftables[14], &reftables[15]),
}; };
static const upb_fielddef fields[37] = { static const upb_fielddef fields[37] = {

@ -348,6 +348,29 @@ local function end_namespace(package, append)
end end
end end
local function well_known_type(m)
local type_map = {}
type_map["google.protobuf.Duration"] = "UPB_WELLKNOWN_DURATION"
type_map["google.protobuf.Timestamp"] = "UPB_WELLKNOWN_TIMESTAMP"
type_map["google.protobuf.Value"] = "UPB_WELLKNOWN_VALUE"
type_map["google.protobuf.ListValue"] = "UPB_WELLKNOWN_LISTVALUE"
type_map["google.protobuf.Struct"] = "UPB_WELLKNOWN_STRUCT"
type_map["google.protobuf.DoubleValue"] = "UPB_WELLKNOWN_DOUBLEVALUE"
type_map["google.protobuf.FloatValue"] = "UPB_WELLKNOWN_FLOATVALUE"
type_map["google.protobuf.Int64Value"] = "UPB_WELLKNOWN_INT64VALUE"
type_map["google.protobuf.UInt64Value"] = "UPB_WELLKNOWN_UINT64VALUE"
type_map["google.protobuf.Int32Value"] = "UPB_WELLKNOWN_INT32VALUE"
type_map["google.protobuf.UInt32Value"] = "UPB_WELLKNOWN_UINT32VALUE"
type_map["google.protobuf.BoolValue"] = "UPB_WELLKNOWN_BOOLVALUE"
type_map["google.protobuf.StringValue"] = "UPB_WELLKNOWN_STRINGVALUE"
type_map["google.protobuf.BytesValue"] = "UPB_WELLKNOWN_BYTESVALUE"
local t = type_map[m:full_name()]
if (t == nil) then
t = "UPB_WELLKNOWN_UNSPECIFIED"
end
return t
end
--[[ --[[
Top-level, exported dumper functions Top-level, exported dumper functions
@ -435,7 +458,7 @@ local function dump_defs_c(filedef, append)
local tables = gettables(m) local tables = gettables(m)
-- UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, -- UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof,
-- refs, ref2s) -- refs, ref2s)
append(' UPB_MSGDEF_INIT("%s", %d, %d, %s, %s, %s, %s,' .. append(' UPB_MSGDEF_INIT("%s", %d, %d, %s, %s, %s, %s, %s,' ..
' &reftables[%d], &reftables[%d]),\n', ' &reftables[%d], &reftables[%d]),\n',
m:full_name(), m:full_name(),
upbtable.msgdef_selector_count(m), upbtable.msgdef_selector_count(m),
@ -444,6 +467,7 @@ local function dump_defs_c(filedef, append)
dumper:strtable(tables.str), dumper:strtable(tables.str),
boolstr(m:_map_entry()), boolstr(m:_map_entry()),
const(m, "syntax"), const(m, "syntax"),
well_known_type(m),
reftable, reftable + 1) reftable, reftable + 1)
reftable = reftable + 2 reftable = reftable + 2
end end

@ -365,6 +365,45 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
return true; return true;
} }
static void assign_msg_wellknowntype(upb_msgdef *m) {
const char *name = upb_msgdef_fullname(m);
if (name == NULL) {
m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED;
return;
}
if (!strcmp(name, "google.protobuf.Duration")) {
m->well_known_type = UPB_WELLKNOWN_DURATION;
} else if (!strcmp(name, "google.protobuf.Timestamp")) {
m->well_known_type = UPB_WELLKNOWN_TIMESTAMP;
} else if (!strcmp(name, "google.protobuf.DoubleValue")) {
m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE;
} else if (!strcmp(name, "google.protobuf.FloatValue")) {
m->well_known_type = UPB_WELLKNOWN_FLOATVALUE;
} else if (!strcmp(name, "google.protobuf.Int64Value")) {
m->well_known_type = UPB_WELLKNOWN_INT64VALUE;
} else if (!strcmp(name, "google.protobuf.UInt64Value")) {
m->well_known_type = UPB_WELLKNOWN_UINT64VALUE;
} else if (!strcmp(name, "google.protobuf.Int32Value")) {
m->well_known_type = UPB_WELLKNOWN_INT32VALUE;
} else if (!strcmp(name, "google.protobuf.UInt32Value")) {
m->well_known_type = UPB_WELLKNOWN_UINT32VALUE;
} else if (!strcmp(name, "google.protobuf.BoolValue")) {
m->well_known_type = UPB_WELLKNOWN_BOOLVALUE;
} else if (!strcmp(name, "google.protobuf.StringValue")) {
m->well_known_type = UPB_WELLKNOWN_STRINGVALUE;
} else if (!strcmp(name, "google.protobuf.BytesValue")) {
m->well_known_type = UPB_WELLKNOWN_BYTESVALUE;
} else if (!strcmp(name, "google.protobuf.Value")) {
m->well_known_type = UPB_WELLKNOWN_VALUE;
} else if (!strcmp(name, "google.protobuf.ListValue")) {
m->well_known_type = UPB_WELLKNOWN_LISTVALUE;
} else if (!strcmp(name, "google.protobuf.Struct")) {
m->well_known_type = UPB_WELLKNOWN_STRUCT;
} else {
m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED;
}
}
bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
size_t i; size_t i;
@ -401,6 +440,8 @@ bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
if (!assign_msg_indices(m, s)) { if (!assign_msg_indices(m, s)) {
goto err; goto err;
} }
assign_msg_wellknowntype(m);
/* m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; */
} else if (e) { } else if (e) {
upb_inttable_compact(&e->iton); upb_inttable_compact(&e->iton);
} }
@ -1337,12 +1378,6 @@ bool upb_fielddef_checkdescriptortype(int32_t type) {
/* upb_msgdef *****************************************************************/ /* upb_msgdef *****************************************************************/
static const char *kDurationFullMessageName = "google.protobuf.Duration";
static const char *kTimestampFullMessageName = "google.protobuf.Timestamp";
static const char *kValueFullMessageName = "google.protobuf.Value";
static const char *kListValueFullMessageName = "google.protobuf.ListValue";
static const char *kStructFullMessageName = "google.protobuf.Struct";
static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit, static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit,
void *closure) { void *closure) {
upb_msg_oneof_iter o; upb_msg_oneof_iter o;
@ -1599,24 +1634,14 @@ bool upb_msgdef_mapentry(const upb_msgdef *m) {
return m->map_entry; return m->map_entry;
} }
bool upb_msgdef_duration(const upb_msgdef *m) { upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kDurationFullMessageName) == 0; return m->well_known_type;
}
bool upb_msgdef_timestamp(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kTimestampFullMessageName) == 0;
}
bool upb_msgdef_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kValueFullMessageName) == 0;
}
bool upb_msgdef_listvalue(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kListValueFullMessageName) == 0;
} }
bool upb_msgdef_structvalue(const upb_msgdef *m) { bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kStructFullMessageName) == 0; upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
return type >= UPB_WELLKNOWN_DOUBLEVALUE &&
type <= UPB_WELLKNOWN_UINT32VALUE;
} }
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) {

@ -279,6 +279,31 @@ typedef enum {
UPB_SYNTAX_PROTO3 = 3 UPB_SYNTAX_PROTO3 = 3
} upb_syntax_t; } upb_syntax_t;
/* All the different kind of well known type messages. For simplicity of check,
* number wrappers and string wrappers are grouped together. Make sure the
* order and merber of these groups are not changed.
*/
typedef enum {
UPB_WELLKNOWN_UNSPECIFIED,
UPB_WELLKNOWN_DURATION,
UPB_WELLKNOWN_TIMESTAMP,
/* number wrappers */
UPB_WELLKNOWN_DOUBLEVALUE,
UPB_WELLKNOWN_FLOATVALUE,
UPB_WELLKNOWN_INT64VALUE,
UPB_WELLKNOWN_UINT64VALUE,
UPB_WELLKNOWN_INT32VALUE,
UPB_WELLKNOWN_UINT32VALUE,
/* string wrappers */
UPB_WELLKNOWN_STRINGVALUE,
UPB_WELLKNOWN_BYTESVALUE,
UPB_WELLKNOWN_BOOLVALUE,
UPB_WELLKNOWN_VALUE,
UPB_WELLKNOWN_LISTVALUE,
UPB_WELLKNOWN_STRUCT
} upb_wellknowntype_t;
/* Maps descriptor type -> upb field type. */ /* Maps descriptor type -> upb field type. */
extern const uint8_t upb_desctype_to_fieldtype[]; extern const uint8_t upb_desctype_to_fieldtype[];
@ -785,20 +810,12 @@ class upb::MessageDef {
void setmapentry(bool map_entry); void setmapentry(bool map_entry);
bool mapentry() const; bool mapentry() const;
/* Is this message a duration? */ /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
bool duration() const; * non-well-known message. */
upb_wellknowntype_t wellknowntype() const;
/* Is this message a timestamp? */
bool timestamp() const;
/* Is this message a value? */ /* Whether is a number wrapper. */
bool value() const; bool isnumberwrapper() const;
/* Is this message a list value? */
bool listvalue() const;
/* Is this message a struct value? */
bool structvalue() const;
/* Iteration over fields. The order is undefined. */ /* Iteration over fields. The order is undefined. */
class field_iterator class field_iterator
@ -941,11 +958,8 @@ bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s); bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s);
void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry); void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry);
bool upb_msgdef_mapentry(const upb_msgdef *m); bool upb_msgdef_mapentry(const upb_msgdef *m);
bool upb_msgdef_duration(const upb_msgdef *m); upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m);
bool upb_msgdef_timestamp(const upb_msgdef *m); bool upb_msgdef_isnumberwrapper(const upb_msgdef *m);
bool upb_msgdef_value(const upb_msgdef *m);
bool upb_msgdef_listvalue(const upb_msgdef *m);
bool upb_msgdef_structvalue(const upb_msgdef *m);
bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax); bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
/* Field lookup in a couple of different variations: /* Field lookup in a couple of different variations:
@ -1885,20 +1899,11 @@ inline void MessageDef::setmapentry(bool map_entry) {
inline bool MessageDef::mapentry() const { inline bool MessageDef::mapentry() const {
return upb_msgdef_mapentry(this); return upb_msgdef_mapentry(this);
} }
inline bool MessageDef::duration() const { inline upb_wellknowntype_t MessageDef::wellknowntype() const {
return upb_msgdef_duration(this); return upb_msgdef_wellknowntype(this);
}
inline bool MessageDef::timestamp() const {
return upb_msgdef_timestamp(this);
}
inline bool MessageDef::value() const {
return upb_msgdef_value(this);
}
inline bool MessageDef::listvalue() const {
return upb_msgdef_listvalue(this);
} }
inline bool MessageDef::structvalue() const { inline bool MessageDef::isnumberwrapper() const {
return upb_msgdef_structvalue(this); return upb_msgdef_isnumberwrapper(this);
} }
inline MessageDef::field_iterator MessageDef::field_begin() { inline MessageDef::field_iterator MessageDef::field_begin() {
return field_iterator(this); return field_iterator(this);

@ -21,28 +21,28 @@ static upb_inttable reftables[268];
#endif #endif
static const upb_msgdef msgs[22] = { static const upb_msgdef msgs[22] = {
UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]), UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[0], &reftables[1]),
UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]), UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[2], &reftables[3]),
UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]), UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[4], &reftables[5]),
UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]), UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[6], &reftables[7]),
UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]), UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[8], &reftables[9]),
UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]), UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[10], &reftables[11]),
UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]), UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[12], &reftables[13]),
UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]), UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[14], &reftables[15]),
UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]), UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[16], &reftables[17]),
UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]), UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[18], &reftables[19]),
UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]), UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[20], &reftables[21]),
UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]), UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[22], &reftables[23]),
UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]), UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[24], &reftables[25]),
UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]), UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[26], &reftables[27]),
UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]), UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[28], &reftables[29]),
UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]), UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[30], &reftables[31]),
UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]), UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[32], &reftables[33]),
UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]), UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[34], &reftables[35]),
UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]), UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[36], &reftables[37]),
UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]), UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[38], &reftables[39]),
UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]), UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[40], &reftables[41]),
UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]), UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[42], &reftables[43]),
}; };
static const upb_fielddef fields[107] = { static const upb_fielddef fields[107] = {

@ -687,6 +687,7 @@ static size_t msg_name(void *closure, const void *hd, const char *buf,
upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL);
upb_descreader_setscopename(r, name); /* Passes ownership of name. */ upb_descreader_setscopename(r, name); /* Passes ownership of name. */
return n; return n;
} }

@ -39,16 +39,6 @@
#define UPB_JSON_MAX_DEPTH 64 #define UPB_JSON_MAX_DEPTH 64
static const char *kDoubleValueFullMessageName = "google.protobuf.DoubleValue";
static const char *kFloatValueFullMessageName = "google.protobuf.FloatValue";
static const char *kInt64ValueFullMessageName = "google.protobuf.Int64Value";
static const char *kUInt64ValueFullMessageName = "google.protobuf.UInt64Value";
static const char *kInt32ValueFullMessageName = "google.protobuf.Int32Value";
static const char *kUInt32ValueFullMessageName = "google.protobuf.UInt32Value";
static const char *kBoolValueFullMessageName = "google.protobuf.BoolValue";
static const char *kStringValueFullMessageName = "google.protobuf.StringValue";
static const char *kBytesValueFullMessageName = "google.protobuf.BytesValue";
/* Type of value message */ /* Type of value message */
enum { enum {
VALUE_NULLVALUE = 0, VALUE_NULLVALUE = 0,
@ -61,6 +51,8 @@ enum {
/* Forward declare */ /* Forward declare */
static bool is_top_level(upb_json_parser *p); static bool is_top_level(upb_json_parser *p);
static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type);
static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type);
static bool is_number_wrapper_object(upb_json_parser *p); static bool is_number_wrapper_object(upb_json_parser *p);
static bool does_number_wrapper_start(upb_json_parser *p); static bool does_number_wrapper_start(upb_json_parser *p);
@ -70,30 +62,6 @@ static bool is_string_wrapper_object(upb_json_parser *p);
static bool does_string_wrapper_start(upb_json_parser *p); static bool does_string_wrapper_start(upb_json_parser *p);
static bool does_string_wrapper_end(upb_json_parser *p); static bool does_string_wrapper_end(upb_json_parser *p);
static bool is_boolean_wrapper_object(upb_json_parser *p);
static bool does_boolean_wrapper_start(upb_json_parser *p);
static bool does_boolean_wrapper_end(upb_json_parser *p);
static bool is_duration_object(upb_json_parser *p);
static bool does_duration_start(upb_json_parser *p);
static bool does_duration_end(upb_json_parser *p);
static bool is_timestamp_object(upb_json_parser *p);
static bool does_timestamp_start(upb_json_parser *p);
static bool does_timestamp_end(upb_json_parser *p);
static bool is_value_object(upb_json_parser *p);
static bool does_value_start(upb_json_parser *p);
static bool does_value_end(upb_json_parser *p);
static bool is_listvalue_object(upb_json_parser *p);
static bool does_listvalue_start(upb_json_parser *p);
static bool does_listvalue_end(upb_json_parser *p);
static bool is_structvalue_object(upb_json_parser *p);
static bool does_structvalue_start(upb_json_parser *p);
static bool does_structvalue_end(upb_json_parser *p);
static void start_wrapper_object(upb_json_parser *p); static void start_wrapper_object(upb_json_parser *p);
static void end_wrapper_object(upb_json_parser *p); static void end_wrapper_object(upb_json_parser *p);
@ -701,7 +669,7 @@ static bool start_number(upb_json_parser *p, const char *ptr) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_number_wrapper_object(p)) { if (is_number_wrapper_object(p)) {
start_wrapper_object(p); start_wrapper_object(p);
} else if (is_value_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_NUMBERVALUE); start_value_object(p, VALUE_NUMBERVALUE);
} else { } else {
return false; return false;
@ -711,7 +679,7 @@ static bool start_number(upb_json_parser *p, const char *ptr) {
return false; return false;
} }
start_wrapper_object(p); start_wrapper_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -751,7 +719,7 @@ static bool end_number(upb_json_parser *p, const char *ptr) {
return true; return true;
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -931,19 +899,19 @@ static bool parser_putbool(upb_json_parser *p, bool val) {
static bool end_bool(upb_json_parser *p, bool val) { static bool end_bool(upb_json_parser *p, bool val) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_boolean_wrapper_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) {
start_wrapper_object(p); start_wrapper_object(p);
} else if (is_value_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_BOOLVALUE); start_value_object(p, VALUE_BOOLVALUE);
} else { } else {
return false; return false;
} }
} else if (does_boolean_wrapper_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_BOOLVALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
start_wrapper_object(p); start_wrapper_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -954,7 +922,7 @@ static bool end_bool(upb_json_parser *p, bool val) {
return false; return false;
} }
if (does_boolean_wrapper_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) {
end_wrapper_object(p); end_wrapper_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -962,7 +930,7 @@ static bool end_bool(upb_json_parser *p, bool val) {
return true; return true;
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -977,12 +945,12 @@ static bool end_null(upb_json_parser *p) {
const char *zero_ptr = "0"; const char *zero_ptr = "0";
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_value_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_NULLVALUE); start_value_object(p, VALUE_NULLVALUE);
} else { } else {
return true; return true;
} }
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -1009,9 +977,10 @@ static bool start_stringval(upb_json_parser *p) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_string_wrapper_object(p)) { if (is_string_wrapper_object(p)) {
start_wrapper_object(p); start_wrapper_object(p);
} else if (is_timestamp_object(p) || is_duration_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
start_object(p); start_object(p);
} else if (is_value_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_STRINGVALUE); start_value_object(p, VALUE_STRINGVALUE);
} else { } else {
return false; return false;
@ -1021,12 +990,13 @@ static bool start_stringval(upb_json_parser *p) {
return false; return false;
} }
start_wrapper_object(p); start_wrapper_object(p);
} else if (does_timestamp_start(p) || does_duration_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
start_object(p); start_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -1087,7 +1057,8 @@ static bool start_stringval(upb_json_parser *p) {
static bool end_stringval_nontop(upb_json_parser *p) { static bool end_stringval_nontop(upb_json_parser *p) {
bool ok = true; bool ok = true;
if (is_timestamp_object(p) || is_duration_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
multipart_end(p); multipart_end(p);
return true; return true;
} }
@ -1169,7 +1140,7 @@ static bool end_stringval(upb_json_parser *p) {
return true; return true;
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1177,7 +1148,8 @@ static bool end_stringval(upb_json_parser *p) {
return true; return true;
} }
if (does_timestamp_end(p) || does_duration_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
end_object(p); end_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1679,19 +1651,19 @@ static bool start_subobject(upb_json_parser *p) {
static bool start_subobject_full(upb_json_parser *p) { static bool start_subobject_full(upb_json_parser *p) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_value_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_STRUCTVALUE); start_value_object(p, VALUE_STRUCTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_structvalue_object(p); start_structvalue_object(p);
} else if (is_structvalue_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) {
start_structvalue_object(p); start_structvalue_object(p);
} else { } else {
return true; return true;
} }
} else if (does_structvalue_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_STRUCT)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_structvalue_object(p); start_structvalue_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_value_object(p, VALUE_STRUCTVALUE); start_value_object(p, VALUE_STRUCTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
@ -1725,14 +1697,14 @@ static void end_subobject(upb_json_parser *p) {
static void end_subobject_full(upb_json_parser *p) { static void end_subobject_full(upb_json_parser *p) {
end_subobject(p); end_subobject(p);
if (does_structvalue_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) {
end_structvalue_object(p); end_structvalue_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
} }
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1745,19 +1717,19 @@ static bool start_array(upb_json_parser *p) {
upb_selector_t sel; upb_selector_t sel;
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_value_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_LISTVALUE); start_value_object(p, VALUE_LISTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_listvalue_object(p); start_listvalue_object(p);
} else if (is_listvalue_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) {
start_listvalue_object(p); start_listvalue_object(p);
} else { } else {
return false; return false;
} }
} else if (does_listvalue_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_LISTVALUE)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_listvalue_object(p); start_listvalue_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_value_object(p, VALUE_LISTVALUE); start_value_object(p, VALUE_LISTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
@ -1798,14 +1770,14 @@ static void end_array(upb_json_parser *p) {
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
upb_sink_endseq(&p->top->sink, sel); upb_sink_endseq(&p->top->sink, sel);
if (does_listvalue_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) {
end_listvalue_object(p); end_listvalue_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
} }
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1830,54 +1802,10 @@ static void end_object(upb_json_parser *p) {
} }
} }
static bool is_double_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kDoubleValueFullMessageName) == 0;
}
static bool is_float_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kFloatValueFullMessageName) == 0;
}
static bool is_int64_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kInt64ValueFullMessageName) == 0;
}
static bool is_uint64_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kUInt64ValueFullMessageName) == 0;
}
static bool is_int32_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kInt32ValueFullMessageName) == 0;
}
static bool is_uint32_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kUInt32ValueFullMessageName) == 0;
}
static bool is_bool_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kBoolValueFullMessageName) == 0;
}
static bool is_string_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kStringValueFullMessageName) == 0;
}
static bool is_bytes_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kBytesValueFullMessageName) == 0;
}
static bool is_number_wrapper(const upb_msgdef *m) {
return is_double_value(m) ||
is_float_value(m) ||
is_int64_value(m) ||
is_uint64_value(m) ||
is_int32_value(m) ||
is_uint32_value(m);
}
static bool is_string_wrapper(const upb_msgdef *m) { static bool is_string_wrapper(const upb_msgdef *m) {
return is_string_value(m) || upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
is_bytes_value(m); return type == UPB_WELLKNOWN_STRINGVALUE ||
type == UPB_WELLKNOWN_BYTESVALUE;
} }
static void start_wrapper_object(upb_json_parser *p) { static void start_wrapper_object(upb_json_parser *p) {
@ -1979,18 +1907,29 @@ static bool is_top_level(upb_json_parser *p) {
return p->top == p->stack && p->top->f == NULL; return p->top == p->stack && p->top->f == NULL;
} }
static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type) {
return p->top->m != NULL && upb_msgdef_wellknowntype(p->top->m) == type;
}
static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
(upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(p->top->f))
== type);
}
static bool does_number_wrapper_start(upb_json_parser *p) { static bool does_number_wrapper_start(upb_json_parser *p) {
return p->top->f != NULL && return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) && upb_fielddef_issubmsg(p->top->f) &&
is_number_wrapper(upb_fielddef_msgsubdef(p->top->f)); upb_msgdef_isnumberwrapper(upb_fielddef_msgsubdef(p->top->f));
} }
static bool does_number_wrapper_end(upb_json_parser *p) { static bool does_number_wrapper_end(upb_json_parser *p) {
return p->top->m != NULL && is_number_wrapper(p->top->m); return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m);
} }
static bool is_number_wrapper_object(upb_json_parser *p) { static bool is_number_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_number_wrapper(p->top->m); return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m);
} }
static bool does_string_wrapper_start(upb_json_parser *p) { static bool does_string_wrapper_start(upb_json_parser *p) {
@ -2007,91 +1946,6 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_string_wrapper(p->top->m); return p->top->m != NULL && is_string_wrapper(p->top->m);
} }
static bool does_boolean_wrapper_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
is_bool_value(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_boolean_wrapper_end(upb_json_parser *p) {
return p->top->m != NULL && is_bool_value(p->top->m);
}
static bool is_boolean_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_bool_value(p->top->m);
}
static bool does_duration_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_duration(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_duration_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_duration(p->top->m);
}
static bool is_duration_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_duration(p->top->m);
}
static bool does_timestamp_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_timestamp(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_timestamp_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_timestamp(p->top->m);
}
static bool is_timestamp_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_timestamp(p->top->m);
}
static bool does_value_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_value(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_value_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_value(p->top->m);
}
static bool is_value_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_value(p->top->m);
}
static bool does_listvalue_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_listvalue(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_listvalue_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_listvalue(p->top->m);
}
static bool is_listvalue_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_listvalue(p->top->m);
}
static bool does_structvalue_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_structvalue(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_structvalue_end(upb_json_parser *p) {
/* return p->top != p->stack && upb_msgdef_structvalue((p->top - 1)->m); */
return p->top->m != NULL && upb_msgdef_structvalue(p->top->m);
}
static bool is_structvalue_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_structvalue(p->top->m);
}
#define CHECK_RETURN_TOP(x) if (!(x)) goto error #define CHECK_RETURN_TOP(x) if (!(x)) goto error
@ -2113,11 +1967,11 @@ static bool is_structvalue_object(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */ * final state once, when the closing '"' is seen. */
#line 2252 "upb/json/parser.rl" #line 2106 "upb/json/parser.rl"
#line 2121 "upb/json/parser.c" #line 1975 "upb/json/parser.c"
static const char _json_actions[] = { static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1, 0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1, 4, 1, 6, 1, 7, 1, 8, 1,
@ -2368,7 +2222,7 @@ static const int json_en_value_machine = 76;
static const int json_en_main = 1; static const int json_en_main = 1;
#line 2255 "upb/json/parser.rl" #line 2109 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size, size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) { const upb_bufhandle *handle) {
@ -2391,7 +2245,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume(parser, buf); capture_resume(parser, buf);
#line 2395 "upb/json/parser.c" #line 2249 "upb/json/parser.c"
{ {
int _klen; int _klen;
unsigned int _trans; unsigned int _trans;
@ -2466,87 +2320,87 @@ _match:
switch ( *_acts++ ) switch ( *_acts++ )
{ {
case 1: case 1:
#line 2126 "upb/json/parser.rl" #line 1980 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 2: case 2:
#line 2128 "upb/json/parser.rl" #line 1982 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 24; goto _again;} } { p--; {stack[top++] = cs; cs = 24; goto _again;} }
break; break;
case 3: case 3:
#line 2132 "upb/json/parser.rl" #line 1986 "upb/json/parser.rl"
{ start_text(parser, p); } { start_text(parser, p); }
break; break;
case 4: case 4:
#line 2133 "upb/json/parser.rl" #line 1987 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); } { CHECK_RETURN_TOP(end_text(parser, p)); }
break; break;
case 5: case 5:
#line 2139 "upb/json/parser.rl" #line 1993 "upb/json/parser.rl"
{ start_hex(parser); } { start_hex(parser); }
break; break;
case 6: case 6:
#line 2140 "upb/json/parser.rl" #line 1994 "upb/json/parser.rl"
{ hexdigit(parser, p); } { hexdigit(parser, p); }
break; break;
case 7: case 7:
#line 2141 "upb/json/parser.rl" #line 1995 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); } { CHECK_RETURN_TOP(end_hex(parser)); }
break; break;
case 8: case 8:
#line 2147 "upb/json/parser.rl" #line 2001 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); } { CHECK_RETURN_TOP(escape(parser, p)); }
break; break;
case 9: case 9:
#line 2153 "upb/json/parser.rl" #line 2007 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 10: case 10:
#line 2165 "upb/json/parser.rl" #line 2019 "upb/json/parser.rl"
{ start_duration_base(parser, p); } { start_duration_base(parser, p); }
break; break;
case 11: case 11:
#line 2166 "upb/json/parser.rl" #line 2020 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_duration_base(parser, p)); } { CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break; break;
case 12: case 12:
#line 2168 "upb/json/parser.rl" #line 2022 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 13: case 13:
#line 2173 "upb/json/parser.rl" #line 2027 "upb/json/parser.rl"
{ start_timestamp_base(parser, p); } { start_timestamp_base(parser, p); }
break; break;
case 14: case 14:
#line 2174 "upb/json/parser.rl" #line 2028 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); }
break; break;
case 15: case 15:
#line 2176 "upb/json/parser.rl" #line 2030 "upb/json/parser.rl"
{ start_timestamp_fraction(parser, p); } { start_timestamp_fraction(parser, p); }
break; break;
case 16: case 16:
#line 2177 "upb/json/parser.rl" #line 2031 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break; break;
case 17: case 17:
#line 2179 "upb/json/parser.rl" #line 2033 "upb/json/parser.rl"
{ start_timestamp_zone(parser, p); } { start_timestamp_zone(parser, p); }
break; break;
case 18: case 18:
#line 2180 "upb/json/parser.rl" #line 2034 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break; break;
case 19: case 19:
#line 2182 "upb/json/parser.rl" #line 2036 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 20: case 20:
#line 2187 "upb/json/parser.rl" #line 2041 "upb/json/parser.rl"
{ {
if (is_timestamp_object(parser)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
{stack[top++] = cs; cs = 48; goto _again;} {stack[top++] = cs; cs = 48; goto _again;}
} else if (is_duration_object(parser)) { } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) {
{stack[top++] = cs; cs = 41; goto _again;} {stack[top++] = cs; cs = 41; goto _again;}
} else { } else {
{stack[top++] = cs; cs = 33; goto _again;} {stack[top++] = cs; cs = 33; goto _again;}
@ -2554,78 +2408,78 @@ _match:
} }
break; break;
case 21: case 21:
#line 2198 "upb/json/parser.rl" #line 2052 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 76; goto _again;} } { p--; {stack[top++] = cs; cs = 76; goto _again;} }
break; break;
case 22: case 22:
#line 2203 "upb/json/parser.rl" #line 2057 "upb/json/parser.rl"
{ start_member(parser); } { start_member(parser); }
break; break;
case 23: case 23:
#line 2204 "upb/json/parser.rl" #line 2058 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_membername(parser)); } { CHECK_RETURN_TOP(end_membername(parser)); }
break; break;
case 24: case 24:
#line 2207 "upb/json/parser.rl" #line 2061 "upb/json/parser.rl"
{ end_member(parser); } { end_member(parser); }
break; break;
case 25: case 25:
#line 2213 "upb/json/parser.rl" #line 2067 "upb/json/parser.rl"
{ start_object(parser); } { start_object(parser); }
break; break;
case 26: case 26:
#line 2216 "upb/json/parser.rl" #line 2070 "upb/json/parser.rl"
{ end_object(parser); } { end_object(parser); }
break; break;
case 27: case 27:
#line 2222 "upb/json/parser.rl" #line 2076 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); } { CHECK_RETURN_TOP(start_array(parser)); }
break; break;
case 28: case 28:
#line 2226 "upb/json/parser.rl" #line 2080 "upb/json/parser.rl"
{ end_array(parser); } { end_array(parser); }
break; break;
case 29: case 29:
#line 2231 "upb/json/parser.rl" #line 2085 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_number(parser, p)); } { CHECK_RETURN_TOP(start_number(parser, p)); }
break; break;
case 30: case 30:
#line 2232 "upb/json/parser.rl" #line 2086 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); } { CHECK_RETURN_TOP(end_number(parser, p)); }
break; break;
case 31: case 31:
#line 2234 "upb/json/parser.rl" #line 2088 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); } { CHECK_RETURN_TOP(start_stringval(parser)); }
break; break;
case 32: case 32:
#line 2235 "upb/json/parser.rl" #line 2089 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_stringval(parser)); } { CHECK_RETURN_TOP(end_stringval(parser)); }
break; break;
case 33: case 33:
#line 2237 "upb/json/parser.rl" #line 2091 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); } { CHECK_RETURN_TOP(end_bool(parser, true)); }
break; break;
case 34: case 34:
#line 2239 "upb/json/parser.rl" #line 2093 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); } { CHECK_RETURN_TOP(end_bool(parser, false)); }
break; break;
case 35: case 35:
#line 2241 "upb/json/parser.rl" #line 2095 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); } { CHECK_RETURN_TOP(end_null(parser)); }
break; break;
case 36: case 36:
#line 2243 "upb/json/parser.rl" #line 2097 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject_full(parser)); } { CHECK_RETURN_TOP(start_subobject_full(parser)); }
break; break;
case 37: case 37:
#line 2244 "upb/json/parser.rl" #line 2098 "upb/json/parser.rl"
{ end_subobject_full(parser); } { end_subobject_full(parser); }
break; break;
case 38: case 38:
#line 2249 "upb/json/parser.rl" #line 2103 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
#line 2629 "upb/json/parser.c" #line 2483 "upb/json/parser.c"
} }
} }
@ -2642,34 +2496,34 @@ _again:
while ( __nacts-- > 0 ) { while ( __nacts-- > 0 ) {
switch ( *__acts++ ) { switch ( *__acts++ ) {
case 0: case 0:
#line 2124 "upb/json/parser.rl" #line 1978 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 26: case 26:
#line 2216 "upb/json/parser.rl" #line 2070 "upb/json/parser.rl"
{ end_object(parser); } { end_object(parser); }
break; break;
case 30: case 30:
#line 2232 "upb/json/parser.rl" #line 2086 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); } { CHECK_RETURN_TOP(end_number(parser, p)); }
break; break;
case 33: case 33:
#line 2237 "upb/json/parser.rl" #line 2091 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); } { CHECK_RETURN_TOP(end_bool(parser, true)); }
break; break;
case 34: case 34:
#line 2239 "upb/json/parser.rl" #line 2093 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); } { CHECK_RETURN_TOP(end_bool(parser, false)); }
break; break;
case 35: case 35:
#line 2241 "upb/json/parser.rl" #line 2095 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); } { CHECK_RETURN_TOP(end_null(parser)); }
break; break;
case 37: case 37:
#line 2244 "upb/json/parser.rl" #line 2098 "upb/json/parser.rl"
{ end_subobject_full(parser); } { end_subobject_full(parser); }
break; break;
#line 2673 "upb/json/parser.c" #line 2527 "upb/json/parser.c"
} }
} }
} }
@ -2677,7 +2531,7 @@ _again:
_out: {} _out: {}
} }
#line 2277 "upb/json/parser.rl" #line 2131 "upb/json/parser.rl"
if (p != pe) { if (p != pe) {
upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
@ -2709,9 +2563,9 @@ bool end(void *closure, const void *hd) {
parse(parser, hd, &eof_ch, 0, NULL); parse(parser, hd, &eof_ch, 0, NULL);
return parser->current_state >= return parser->current_state >=
#line 2713 "upb/json/parser.c" #line 2567 "upb/json/parser.c"
105 105
#line 2307 "upb/json/parser.rl" #line 2161 "upb/json/parser.rl"
; ;
} }
@ -2726,13 +2580,13 @@ static void json_parser_reset(upb_json_parser *p) {
/* Emit Ragel initialization of the parser. */ /* Emit Ragel initialization of the parser. */
#line 2730 "upb/json/parser.c" #line 2584 "upb/json/parser.c"
{ {
cs = json_start; cs = json_start;
top = 0; top = 0;
} }
#line 2321 "upb/json/parser.rl" #line 2175 "upb/json/parser.rl"
p->current_state = cs; p->current_state = cs;
p->parser_top = top; p->parser_top = top;
accumulate_clear(p); accumulate_clear(p);

@ -37,16 +37,6 @@
#define UPB_JSON_MAX_DEPTH 64 #define UPB_JSON_MAX_DEPTH 64
static const char *kDoubleValueFullMessageName = "google.protobuf.DoubleValue";
static const char *kFloatValueFullMessageName = "google.protobuf.FloatValue";
static const char *kInt64ValueFullMessageName = "google.protobuf.Int64Value";
static const char *kUInt64ValueFullMessageName = "google.protobuf.UInt64Value";
static const char *kInt32ValueFullMessageName = "google.protobuf.Int32Value";
static const char *kUInt32ValueFullMessageName = "google.protobuf.UInt32Value";
static const char *kBoolValueFullMessageName = "google.protobuf.BoolValue";
static const char *kStringValueFullMessageName = "google.protobuf.StringValue";
static const char *kBytesValueFullMessageName = "google.protobuf.BytesValue";
/* Type of value message */ /* Type of value message */
enum { enum {
VALUE_NULLVALUE = 0, VALUE_NULLVALUE = 0,
@ -59,6 +49,8 @@ enum {
/* Forward declare */ /* Forward declare */
static bool is_top_level(upb_json_parser *p); static bool is_top_level(upb_json_parser *p);
static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type);
static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type);
static bool is_number_wrapper_object(upb_json_parser *p); static bool is_number_wrapper_object(upb_json_parser *p);
static bool does_number_wrapper_start(upb_json_parser *p); static bool does_number_wrapper_start(upb_json_parser *p);
@ -68,30 +60,6 @@ static bool is_string_wrapper_object(upb_json_parser *p);
static bool does_string_wrapper_start(upb_json_parser *p); static bool does_string_wrapper_start(upb_json_parser *p);
static bool does_string_wrapper_end(upb_json_parser *p); static bool does_string_wrapper_end(upb_json_parser *p);
static bool is_boolean_wrapper_object(upb_json_parser *p);
static bool does_boolean_wrapper_start(upb_json_parser *p);
static bool does_boolean_wrapper_end(upb_json_parser *p);
static bool is_duration_object(upb_json_parser *p);
static bool does_duration_start(upb_json_parser *p);
static bool does_duration_end(upb_json_parser *p);
static bool is_timestamp_object(upb_json_parser *p);
static bool does_timestamp_start(upb_json_parser *p);
static bool does_timestamp_end(upb_json_parser *p);
static bool is_value_object(upb_json_parser *p);
static bool does_value_start(upb_json_parser *p);
static bool does_value_end(upb_json_parser *p);
static bool is_listvalue_object(upb_json_parser *p);
static bool does_listvalue_start(upb_json_parser *p);
static bool does_listvalue_end(upb_json_parser *p);
static bool is_structvalue_object(upb_json_parser *p);
static bool does_structvalue_start(upb_json_parser *p);
static bool does_structvalue_end(upb_json_parser *p);
static void start_wrapper_object(upb_json_parser *p); static void start_wrapper_object(upb_json_parser *p);
static void end_wrapper_object(upb_json_parser *p); static void end_wrapper_object(upb_json_parser *p);
@ -699,7 +667,7 @@ static bool start_number(upb_json_parser *p, const char *ptr) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_number_wrapper_object(p)) { if (is_number_wrapper_object(p)) {
start_wrapper_object(p); start_wrapper_object(p);
} else if (is_value_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_NUMBERVALUE); start_value_object(p, VALUE_NUMBERVALUE);
} else { } else {
return false; return false;
@ -709,7 +677,7 @@ static bool start_number(upb_json_parser *p, const char *ptr) {
return false; return false;
} }
start_wrapper_object(p); start_wrapper_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -749,7 +717,7 @@ static bool end_number(upb_json_parser *p, const char *ptr) {
return true; return true;
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -929,19 +897,19 @@ static bool parser_putbool(upb_json_parser *p, bool val) {
static bool end_bool(upb_json_parser *p, bool val) { static bool end_bool(upb_json_parser *p, bool val) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_boolean_wrapper_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) {
start_wrapper_object(p); start_wrapper_object(p);
} else if (is_value_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_BOOLVALUE); start_value_object(p, VALUE_BOOLVALUE);
} else { } else {
return false; return false;
} }
} else if (does_boolean_wrapper_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_BOOLVALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
start_wrapper_object(p); start_wrapper_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -952,7 +920,7 @@ static bool end_bool(upb_json_parser *p, bool val) {
return false; return false;
} }
if (does_boolean_wrapper_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) {
end_wrapper_object(p); end_wrapper_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -960,7 +928,7 @@ static bool end_bool(upb_json_parser *p, bool val) {
return true; return true;
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -975,12 +943,12 @@ static bool end_null(upb_json_parser *p) {
const char *zero_ptr = "0"; const char *zero_ptr = "0";
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_value_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_NULLVALUE); start_value_object(p, VALUE_NULLVALUE);
} else { } else {
return true; return true;
} }
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -1007,9 +975,10 @@ static bool start_stringval(upb_json_parser *p) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_string_wrapper_object(p)) { if (is_string_wrapper_object(p)) {
start_wrapper_object(p); start_wrapper_object(p);
} else if (is_timestamp_object(p) || is_duration_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
start_object(p); start_object(p);
} else if (is_value_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_STRINGVALUE); start_value_object(p, VALUE_STRINGVALUE);
} else { } else {
return false; return false;
@ -1019,12 +988,13 @@ static bool start_stringval(upb_json_parser *p) {
return false; return false;
} }
start_wrapper_object(p); start_wrapper_object(p);
} else if (does_timestamp_start(p) || does_duration_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
start_object(p); start_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) { if (!start_subobject(p)) {
return false; return false;
} }
@ -1085,7 +1055,8 @@ static bool start_stringval(upb_json_parser *p) {
static bool end_stringval_nontop(upb_json_parser *p) { static bool end_stringval_nontop(upb_json_parser *p) {
bool ok = true; bool ok = true;
if (is_timestamp_object(p) || is_duration_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
multipart_end(p); multipart_end(p);
return true; return true;
} }
@ -1167,7 +1138,7 @@ static bool end_stringval(upb_json_parser *p) {
return true; return true;
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1175,7 +1146,8 @@ static bool end_stringval(upb_json_parser *p) {
return true; return true;
} }
if (does_timestamp_end(p) || does_duration_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
end_object(p); end_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1677,19 +1649,19 @@ static bool start_subobject(upb_json_parser *p) {
static bool start_subobject_full(upb_json_parser *p) { static bool start_subobject_full(upb_json_parser *p) {
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_value_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_STRUCTVALUE); start_value_object(p, VALUE_STRUCTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_structvalue_object(p); start_structvalue_object(p);
} else if (is_structvalue_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) {
start_structvalue_object(p); start_structvalue_object(p);
} else { } else {
return true; return true;
} }
} else if (does_structvalue_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_STRUCT)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_structvalue_object(p); start_structvalue_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_value_object(p, VALUE_STRUCTVALUE); start_value_object(p, VALUE_STRUCTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
@ -1723,14 +1695,14 @@ static void end_subobject(upb_json_parser *p) {
static void end_subobject_full(upb_json_parser *p) { static void end_subobject_full(upb_json_parser *p) {
end_subobject(p); end_subobject(p);
if (does_structvalue_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) {
end_structvalue_object(p); end_structvalue_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
} }
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1743,19 +1715,19 @@ static bool start_array(upb_json_parser *p) {
upb_selector_t sel; upb_selector_t sel;
if (is_top_level(p)) { if (is_top_level(p)) {
if (is_value_object(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
start_value_object(p, VALUE_LISTVALUE); start_value_object(p, VALUE_LISTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_listvalue_object(p); start_listvalue_object(p);
} else if (is_listvalue_object(p)) { } else if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) {
start_listvalue_object(p); start_listvalue_object(p);
} else { } else {
return false; return false;
} }
} else if (does_listvalue_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_LISTVALUE)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_listvalue_object(p); start_listvalue_object(p);
} else if (does_value_start(p)) { } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
start_value_object(p, VALUE_LISTVALUE); start_value_object(p, VALUE_LISTVALUE);
if (!start_subobject(p)) return false; if (!start_subobject(p)) return false;
@ -1796,14 +1768,14 @@ static void end_array(upb_json_parser *p) {
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
upb_sink_endseq(&p->top->sink, sel); upb_sink_endseq(&p->top->sink, sel);
if (does_listvalue_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) {
end_listvalue_object(p); end_listvalue_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
} }
} }
if (does_value_end(p)) { if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
end_value_object(p); end_value_object(p);
if (!is_top_level(p)) { if (!is_top_level(p)) {
end_subobject(p); end_subobject(p);
@ -1828,54 +1800,10 @@ static void end_object(upb_json_parser *p) {
} }
} }
static bool is_double_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kDoubleValueFullMessageName) == 0;
}
static bool is_float_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kFloatValueFullMessageName) == 0;
}
static bool is_int64_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kInt64ValueFullMessageName) == 0;
}
static bool is_uint64_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kUInt64ValueFullMessageName) == 0;
}
static bool is_int32_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kInt32ValueFullMessageName) == 0;
}
static bool is_uint32_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kUInt32ValueFullMessageName) == 0;
}
static bool is_bool_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kBoolValueFullMessageName) == 0;
}
static bool is_string_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kStringValueFullMessageName) == 0;
}
static bool is_bytes_value(const upb_msgdef *m) {
return strcmp(upb_msgdef_fullname(m), kBytesValueFullMessageName) == 0;
}
static bool is_number_wrapper(const upb_msgdef *m) {
return is_double_value(m) ||
is_float_value(m) ||
is_int64_value(m) ||
is_uint64_value(m) ||
is_int32_value(m) ||
is_uint32_value(m);
}
static bool is_string_wrapper(const upb_msgdef *m) { static bool is_string_wrapper(const upb_msgdef *m) {
return is_string_value(m) || upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
is_bytes_value(m); return type == UPB_WELLKNOWN_STRINGVALUE ||
type == UPB_WELLKNOWN_BYTESVALUE;
} }
static void start_wrapper_object(upb_json_parser *p) { static void start_wrapper_object(upb_json_parser *p) {
@ -1977,18 +1905,29 @@ static bool is_top_level(upb_json_parser *p) {
return p->top == p->stack && p->top->f == NULL; return p->top == p->stack && p->top->f == NULL;
} }
static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type) {
return p->top->m != NULL && upb_msgdef_wellknowntype(p->top->m) == type;
}
static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
(upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(p->top->f))
== type);
}
static bool does_number_wrapper_start(upb_json_parser *p) { static bool does_number_wrapper_start(upb_json_parser *p) {
return p->top->f != NULL && return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) && upb_fielddef_issubmsg(p->top->f) &&
is_number_wrapper(upb_fielddef_msgsubdef(p->top->f)); upb_msgdef_isnumberwrapper(upb_fielddef_msgsubdef(p->top->f));
} }
static bool does_number_wrapper_end(upb_json_parser *p) { static bool does_number_wrapper_end(upb_json_parser *p) {
return p->top->m != NULL && is_number_wrapper(p->top->m); return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m);
} }
static bool is_number_wrapper_object(upb_json_parser *p) { static bool is_number_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_number_wrapper(p->top->m); return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m);
} }
static bool does_string_wrapper_start(upb_json_parser *p) { static bool does_string_wrapper_start(upb_json_parser *p) {
@ -2005,91 +1944,6 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_string_wrapper(p->top->m); return p->top->m != NULL && is_string_wrapper(p->top->m);
} }
static bool does_boolean_wrapper_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
is_bool_value(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_boolean_wrapper_end(upb_json_parser *p) {
return p->top->m != NULL && is_bool_value(p->top->m);
}
static bool is_boolean_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_bool_value(p->top->m);
}
static bool does_duration_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_duration(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_duration_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_duration(p->top->m);
}
static bool is_duration_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_duration(p->top->m);
}
static bool does_timestamp_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_timestamp(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_timestamp_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_timestamp(p->top->m);
}
static bool is_timestamp_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_timestamp(p->top->m);
}
static bool does_value_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_value(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_value_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_value(p->top->m);
}
static bool is_value_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_value(p->top->m);
}
static bool does_listvalue_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_listvalue(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_listvalue_end(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_listvalue(p->top->m);
}
static bool is_listvalue_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_listvalue(p->top->m);
}
static bool does_structvalue_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
upb_msgdef_structvalue(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_structvalue_end(upb_json_parser *p) {
/* return p->top != p->stack && upb_msgdef_structvalue((p->top - 1)->m); */
return p->top->m != NULL && upb_msgdef_structvalue(p->top->m);
}
static bool is_structvalue_object(upb_json_parser *p) {
return p->top->m != NULL && upb_msgdef_structvalue(p->top->m);
}
#define CHECK_RETURN_TOP(x) if (!(x)) goto error #define CHECK_RETURN_TOP(x) if (!(x)) goto error
@ -2185,9 +2039,9 @@ static bool is_structvalue_object(upb_json_parser *p) {
string = string =
'"' '"'
@{ @{
if (is_timestamp_object(parser)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
fcall timestamp_machine; fcall timestamp_machine;
} else if (is_duration_object(parser)) { } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) {
fcall duration_machine; fcall duration_machine;
} else { } else {
fcall string_machine; fcall string_machine;

@ -708,6 +708,54 @@ static bool putnanos(void *closure, const void *handler_data,
return true; return true;
} }
static void *scalar_startstr_nokey(void *closure, const void *handler_data,
size_t size_hint) {
upb_json_printer *p = closure;
UPB_UNUSED(handler_data);
UPB_UNUSED(size_hint);
print_data(p, "\"", 1);
return p;
}
static size_t putstr_nokey(void *closure, const void *handler_data,
const char *str, size_t len,
const upb_bufhandle *handle) {
upb_json_printer *p = closure;
UPB_UNUSED(handler_data);
UPB_UNUSED(handle);
print_data(p, "\"", 1);
putstring(p, str, len);
print_data(p, "\"", 1);
return len + 2;
}
static void *startseq_nokey(void *closure, const void *handler_data) {
upb_json_printer *p = closure;
UPB_UNUSED(handler_data);
p->depth_++;
p->first_elem_[p->depth_] = true;
print_data(p, "[", 1);
return closure;
}
static void *startmap_nokey(void *closure, const void *handler_data) {
upb_json_printer *p = closure;
UPB_UNUSED(handler_data);
p->depth_++;
p->first_elem_[p->depth_] = true;
print_data(p, "{", 1);
return closure;
}
static bool putnull(void *closure, const void *handler_data,
int32_t null) {
upb_json_printer *p = closure;
print_data(p, "null", 4);
UPB_UNUSED(handler_data);
UPB_UNUSED(null);
return true;
}
static bool printer_startdurationmsg(void *closure, const void *handler_data) { static bool printer_startdurationmsg(void *closure, const void *handler_data) {
upb_json_printer *p = closure; upb_json_printer *p = closure;
UPB_UNUSED(handler_data); UPB_UNUSED(handler_data);
@ -852,6 +900,26 @@ static bool printer_endtimestampmsg(void *closure, const void *handler_data,
return true; return true;
} }
static bool printer_startmsg_noframe(void *closure, const void *handler_data) {
upb_json_printer *p = closure;
UPB_UNUSED(handler_data);
if (p->depth_ == 0) {
upb_bytessink_start(p->output_, 0, &p->subc_);
}
return true;
}
static bool printer_endmsg_noframe(
void *closure, const void *handler_data, upb_status *s) {
upb_json_printer *p = closure;
UPB_UNUSED(handler_data);
UPB_UNUSED(s);
if (p->depth_ == 0) {
upb_bytessink_end(p->output_);
}
return true;
}
/* Set up handlers for a duration submessage. */ /* Set up handlers for a duration submessage. */
void printer_sethandlers_duration(const void *closure, upb_handlers *h) { void printer_sethandlers_duration(const void *closure, upb_handlers *h) {
const upb_msgdef *md = upb_handlers_msgdef(h); const upb_msgdef *md = upb_handlers_msgdef(h);
@ -891,6 +959,102 @@ void printer_sethandlers_timestamp(const void *closure, upb_handlers *h) {
UPB_UNUSED(closure); UPB_UNUSED(closure);
} }
void printer_sethandlers_value(const void *closure, upb_handlers *h) {
const upb_msgdef *md = upb_handlers_msgdef(h);
upb_msg_field_iter i;
upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr);
upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr);
upb_msg_field_begin(&i, md);
for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) {
const upb_fielddef *f = upb_msg_iter_field(&i);
switch (upb_fielddef_type(f)) {
case UPB_TYPE_ENUM:
upb_handlers_setint32(h, f, putnull, &empty_attr);
break;
case UPB_TYPE_DOUBLE:
upb_handlers_setdouble(h, f, putdouble, &empty_attr);
break;
case UPB_TYPE_STRING:
upb_handlers_setstartstr(h, f, scalar_startstr_nokey, &empty_attr);
upb_handlers_setstring(h, f, scalar_str, &empty_attr);
upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr);
break;
case UPB_TYPE_BOOL:
upb_handlers_setbool(h, f, putbool, &empty_attr);
break;
case UPB_TYPE_MESSAGE:
break;
default:
UPB_ASSERT(false);
break;
}
}
UPB_UNUSED(closure);
}
#define WRAPPER_SETHANDLERS(wrapper, type, putmethod) \
void printer_sethandlers_##wrapper(const void *closure, upb_handlers *h) { \
const upb_msgdef *md = upb_handlers_msgdef(h); \
const upb_fielddef* f = upb_msgdef_itof(md, 1); \
upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; \
upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); \
upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); \
upb_handlers_set##type(h, f, putmethod, &empty_attr); \
UPB_UNUSED(closure); \
}
WRAPPER_SETHANDLERS(doublevalue, double, putdouble)
WRAPPER_SETHANDLERS(floatvalue, float, putfloat)
WRAPPER_SETHANDLERS(int64value, int64, putint64_t)
WRAPPER_SETHANDLERS(uint64value, uint64, putuint64_t)
WRAPPER_SETHANDLERS(int32value, int32, putint32_t)
WRAPPER_SETHANDLERS(uint32value, uint32, putuint32_t)
WRAPPER_SETHANDLERS(boolvalue, bool, putbool)
WRAPPER_SETHANDLERS(stringvalue, string, putstr_nokey)
WRAPPER_SETHANDLERS(bytesvalue, string, putbytes)
#undef WRAPPER_SETHANDLERS
void printer_sethandlers_listvalue(const void *closure, upb_handlers *h) {
const upb_msgdef *md = upb_handlers_msgdef(h);
const upb_fielddef* f = upb_msgdef_itof(md, 1);
upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
upb_handlers_setstartseq(h, f, startseq_nokey, &empty_attr);
upb_handlers_setendseq(h, f, endseq, &empty_attr);
upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr);
upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr);
upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr);
UPB_UNUSED(closure);
}
void printer_sethandlers_structvalue(const void *closure, upb_handlers *h) {
const upb_msgdef *md = upb_handlers_msgdef(h);
const upb_fielddef* f = upb_msgdef_itof(md, 1);
upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
upb_handlers_setstartseq(h, f, startmap_nokey, &empty_attr);
upb_handlers_setendseq(h, f, endmap, &empty_attr);
upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr);
upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr);
upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr);
UPB_UNUSED(closure);
}
void printer_sethandlers(const void *closure, upb_handlers *h) { void printer_sethandlers(const void *closure, upb_handlers *h) {
const upb_msgdef *md = upb_handlers_msgdef(h); const upb_msgdef *md = upb_handlers_msgdef(h);
bool is_mapentry = upb_msgdef_mapentry(md); bool is_mapentry = upb_msgdef_mapentry(md);
@ -906,14 +1070,40 @@ void printer_sethandlers(const void *closure, upb_handlers *h) {
return; return;
} }
if (upb_msgdef_duration(md)) { switch (upb_msgdef_wellknowntype(md)) {
case UPB_WELLKNOWN_UNSPECIFIED:
break;
case UPB_WELLKNOWN_DURATION:
printer_sethandlers_duration(closure, h); printer_sethandlers_duration(closure, h);
return; return;
} case UPB_WELLKNOWN_TIMESTAMP:
if (upb_msgdef_timestamp(md)) {
printer_sethandlers_timestamp(closure, h); printer_sethandlers_timestamp(closure, h);
return; return;
case UPB_WELLKNOWN_VALUE:
printer_sethandlers_value(closure, h);
return;
case UPB_WELLKNOWN_LISTVALUE:
printer_sethandlers_listvalue(closure, h);
return;
case UPB_WELLKNOWN_STRUCT:
printer_sethandlers_structvalue(closure, h);
return;
#define WRAPPER(wellknowntype, name) \
case wellknowntype: \
printer_sethandlers_##name(closure, h); \
return; \
WRAPPER(UPB_WELLKNOWN_DOUBLEVALUE, doublevalue);
WRAPPER(UPB_WELLKNOWN_FLOATVALUE, floatvalue);
WRAPPER(UPB_WELLKNOWN_INT64VALUE, int64value);
WRAPPER(UPB_WELLKNOWN_UINT64VALUE, uint64value);
WRAPPER(UPB_WELLKNOWN_INT32VALUE, int32value);
WRAPPER(UPB_WELLKNOWN_UINT32VALUE, uint32value);
WRAPPER(UPB_WELLKNOWN_BOOLVALUE, boolvalue);
WRAPPER(UPB_WELLKNOWN_STRINGVALUE, stringvalue);
WRAPPER(UPB_WELLKNOWN_BYTESVALUE, bytesvalue);
#undef WRAPPER
} }
upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr);

@ -115,6 +115,10 @@ struct upb_msgdef {
/* Whether this message has proto2 or proto3 semantics. */ /* Whether this message has proto2 or proto3 semantics. */
upb_syntax_t syntax; upb_syntax_t syntax;
/* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
* non-well-known message. */
upb_wellknowntype_t well_known_type;
/* TODO(haberman): proper extension ranges (there can be multiple). */ /* TODO(haberman): proper extension ranges (there can be multiple). */
}; };
@ -123,10 +127,11 @@ extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
/* TODO: also support static initialization of the oneofs table. This will be /* TODO: also support static initialization of the oneofs table. This will be
* needed if we compile in descriptors that contain oneofs. */ * needed if we compile in descriptors that contain oneofs. */
#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
map_entry, syntax, refs, ref2s) \ map_entry, syntax, well_known_type, refs, ref2s) \
{ \ { \
UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
selector_count, submsg_field_count, itof, ntof, map_entry, syntax \ selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \
well_known_type \
} }

Loading…
Cancel
Save