summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-04-19 15:41:33 -0700
committerJoshua Haberman <jhaberman@gmail.com>2016-04-19 15:41:33 -0700
commite6fa3f9d869765544b8e424e8573fe8d9af35534 (patch)
tree3e56beb3bd80470ddad130b2c7f703fb5bb6b5fd
parent68bc62a7fa5febbf5c8ab2fe8f6171121d18690f (diff)
Changed schema for JSON test to be defined in a .proto file. (#54)
* Changed schema for JSON test to be defined in a .proto file. Before we had lots of code to build these schemas manually, but this was verbose and made it difficult to add to the schema easily. Now we can just write a .proto file and adding fields is easy. To avoid making the tests depend on upbc (and thus Lua) we check in the generated schema. * Made protobuf-compiler a dependency of "make genfiles." * For genfiles download recent protoc that can handle proto3. * Only use new protoc for genfiles.
-rw-r--r--Makefile29
-rw-r--r--tests/json/test.proto42
-rw-r--r--tests/json/test.proto.pbbin0 -> 1883 bytes
-rw-r--r--tests/json/test.upbdefs.c315
-rw-r--r--tests/json/test.upbdefs.h246
-rw-r--r--tests/json/test_json.cc155
-rw-r--r--tools/dump_cinit.lua30
-rwxr-xr-xtravis.sh6
-rw-r--r--upb/bindings/lua/upb.c17
-rw-r--r--upb/def.c13
-rw-r--r--upb/def.h23
-rw-r--r--upb/descriptor/descriptor.pbbin5012 -> 6341 bytes
-rw-r--r--upb/descriptor/descriptor.upbdefs.c50
-rw-r--r--upb/descriptor/descriptor.upbdefs.h168
-rw-r--r--upb/descriptor/reader.c13
-rw-r--r--upb/structdefs.int.h12
16 files changed, 834 insertions, 285 deletions
diff --git a/Makefile b/Makefile
index dc5467a..966168b 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@
# * -DUPB_THREAD_UNSAFE: remove all thread-safety.
.PHONY: all lib clean tests test descriptorgen amalgamate
-.PHONY: clean_leave_profile
+.PHONY: clean_leave_profile genfiles
# Prevents the deletion of intermediate files.
.SECONDARY:
@@ -249,12 +249,23 @@ obj/upb/%.lo: upb/%.cc | $$(@D)/.
# Regenerating the auto-generated files in upb/.
upb/descriptor/descriptor.pb: upb/descriptor/descriptor.proto
- @# TODO: replace with upbc
- protoc upb/descriptor/descriptor.proto -oupb/descriptor/descriptor.pb
-genfiles: upb/descriptor/descriptor.pb tools/upbc
- ./tools/upbc upb/descriptor/descriptor.pb
- $(LUA) third_party/dynasm/dynasm.lua -c upb/pb/compile_decoder_x64.dasc > upb/pb/compile_decoder_x64.h || (rm upb/pb/compile_decoder_x64.h ; false)
+# "genfiles" includes Proto schemas we need for tests
+# For the moment we check in the *.upbdefs.* generated files so that people
+# can build and run the tests without Lua as a build dependency.
+
+genfiles: tools/upbc
+ @# TODO: replace protoc with upbc when upb can parse .proto files
+ $(E) PROTOC upb/descriptor/descriptor.proto
+ $(Q) protoc upb/descriptor/descriptor.proto -oupb/descriptor/descriptor.pb
+ $(E) UPBC upb/descriptor/descriptor.pb
+ $(Q) ./tools/upbc upb/descriptor/descriptor.pb
+ $(E) PROTOC tests/json/test.proto
+ $(Q) protoc tests/json/test.proto -otests/json/test.proto.pb
+ $(E) UPBC tests/json/test.proto.pb
+ $(Q) ./tools/upbc tests/json/test.proto.pb
+ $(E) DYNASM upb/pb/compile_decoder_x64.dasc
+ $(Q) $(LUA) third_party/dynasm/dynasm.lua -c upb/pb/compile_decoder_x64.dasc > upb/pb/compile_decoder_x64.h || (rm upb/pb/compile_decoder_x64.h ; false)
# upbc depends on these Lua extensions.
UPBC_LUA_EXTS = \
@@ -295,6 +306,10 @@ CC_TESTS = \
TESTS=$(C_TESTS) $(CC_TESTS)
tests: $(TESTS)
+tests/json/test.upbdefs.o: tests/json/test.upbdefs.c
+ $(E) CC $<
+ $(Q) $(CC) $(OPT) $(CSTD) $(WARNFLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
tests/testmain.o: tests/testmain.cc
$(E) CXX $<
$(Q) $(CXX) $(OPT) $(CXXSTD) $(WARNFLAGS_CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
@@ -319,7 +334,7 @@ tests/pb/test_decoder: LIBS = lib/libupb.pb.a lib/libupb.a $(EXTRA_LIBS)
tests/pb/test_encoder: LIBS = lib/libupb.pb.a lib/libupb.descriptor.a lib/libupb.a $(EXTRA_LIBS)
tests/test_cpp: LIBS = $(LOAD_DESCRIPTOR_LIBS) lib/libupb.a $(EXTRA_LIBS)
tests/test_table: LIBS = lib/libupb.a $(EXTRA_LIBS)
-tests/json/test_json: LIBS = lib/libupb.a lib/libupb.json.a $(EXTRA_LIBS)
+tests/json/test_json: LIBS = lib/libupb.a lib/libupb.json.a tests/json/test.upbdefs.o $(EXTRA_LIBS)
tests/test.proto.pb: tests/test.proto
@# TODO: add .proto file parser to upb so this isn't necessary.
diff --git a/tests/json/test.proto b/tests/json/test.proto
new file mode 100644
index 0000000..e659001
--- /dev/null
+++ b/tests/json/test.proto
@@ -0,0 +1,42 @@
+syntax = "proto3";
+
+package upb.test.json;
+
+message TestMessage {
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ int32 optional_uint32 = 3;
+ int64 optional_uint64 = 4;
+ string optional_string = 5;
+ bytes optional_bytes = 6;
+ bool optional_bool = 7;
+ SubMessage optional_msg = 8;
+ MyEnum optional_enum = 9;
+
+ repeated int32 repeated_int32 = 11;
+ repeated int64 repeated_int64 = 12;
+ repeated uint32 repeated_uint32 = 13;
+ repeated uint64 repeated_uint64 = 14;
+ repeated string repeated_string = 15;
+ repeated bytes repeated_bytes = 16;
+ repeated bool repeated_bool = 17;
+ repeated SubMessage repeated_msg = 18;
+ repeated MyEnum repeated_enum = 19;
+
+ map<string, string> map_string_string = 20;
+ map<int32, string> map_int32_string = 21;
+ map<bool, string> map_bool_string = 22;
+ map<string, int32> map_string_int32 = 23;
+ map<string, bool> map_string_bool = 24;
+ map<string, SubMessage> map_string_msg = 25;
+}
+
+message SubMessage {
+ int32 foo = 1;
+}
+
+enum MyEnum {
+ A = 0;
+ B = 1;
+ C = 2;
+}
diff --git a/tests/json/test.proto.pb b/tests/json/test.proto.pb
new file mode 100644
index 0000000..5da355d
--- /dev/null
+++ b/tests/json/test.proto.pb
Binary files differ
diff --git a/tests/json/test.upbdefs.c b/tests/json/test.upbdefs.c
new file mode 100644
index 0000000..d270090
--- /dev/null
+++ b/tests/json/test.upbdefs.c
@@ -0,0 +1,315 @@
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * tests/json/test.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+#include <assert.h>
+
+#include "upb/def.h"
+#include "upb/structdefs.int.h"
+
+static const upb_msgdef msgs[8];
+static const upb_fielddef fields[37];
+static const upb_enumdef enums[1];
+static const upb_tabent strentries[64];
+static const upb_tabval arrays[49];
+
+#ifdef UPB_DEBUG_REFS
+static upb_inttable reftables[92];
+#endif
+
+static const upb_msgdef msgs[8] = {
+ UPB_MSGDEF_INIT("upb.test.json.SubMessage", 3, 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.TestMessage", 72, 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.MapBoolStringEntry", 6, 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.MapInt32StringEntry", 6, 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.MapStringBoolEntry", 6, 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.MapStringInt32Entry", 6, 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.MapStringMsgEntry", 7, 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.MapStringStringEntry", 8, 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]),
+};
+
+static const upb_fielddef fields[37] = {
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "foo", 1, &msgs[0], NULL, 2, 0, {0},&reftables[16], &reftables[17]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "key", 1, &msgs[7], NULL, 2, 0, {0},&reftables[18], &reftables[19]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "key", 1, &msgs[3], NULL, 2, 0, {0},&reftables[20], &reftables[21]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "key", 1, &msgs[2], NULL, 2, 0, {0},&reftables[22], &reftables[23]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "key", 1, &msgs[5], NULL, 2, 0, {0},&reftables[24], &reftables[25]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "key", 1, &msgs[4], NULL, 2, 0, {0},&reftables[26], &reftables[27]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "key", 1, &msgs[6], NULL, 4, 1, {0},&reftables[28], &reftables[29]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "map_bool_string", 22, &msgs[1], (const upb_def*)(&msgs[2]), 22, 4, {0},&reftables[30], &reftables[31]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "map_int32_string", 21, &msgs[1], (const upb_def*)(&msgs[3]), 19, 3, {0},&reftables[32], &reftables[33]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "map_string_bool", 24, &msgs[1], (const upb_def*)(&msgs[4]), 28, 6, {0},&reftables[34], &reftables[35]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "map_string_int32", 23, &msgs[1], (const upb_def*)(&msgs[5]), 25, 5, {0},&reftables[36], &reftables[37]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "map_string_msg", 25, &msgs[1], (const upb_def*)(&msgs[6]), 31, 7, {0},&reftables[38], &reftables[39]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "map_string_string", 20, &msgs[1], (const upb_def*)(&msgs[7]), 16, 2, {0},&reftables[40], &reftables[41]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "optional_bool", 7, &msgs[1], NULL, 42, 14, {0},&reftables[42], &reftables[43]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "optional_bytes", 6, &msgs[1], NULL, 39, 13, {0},&reftables[44], &reftables[45]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optional_enum", 9, &msgs[1], (const upb_def*)(&enums[0]), 43, 15, {0},&reftables[46], &reftables[47]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "optional_int32", 1, &msgs[1], NULL, 32, 8, {0},&reftables[48], &reftables[49]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "optional_int64", 2, &msgs[1], NULL, 33, 9, {0},&reftables[50], &reftables[51]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "optional_msg", 8, &msgs[1], (const upb_def*)(&msgs[0]), 10, 0, {0},&reftables[52], &reftables[53]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "optional_string", 5, &msgs[1], NULL, 36, 12, {0},&reftables[54], &reftables[55]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "optional_uint32", 3, &msgs[1], NULL, 34, 10, {0},&reftables[56], &reftables[57]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "optional_uint64", 4, &msgs[1], NULL, 35, 11, {0},&reftables[58], &reftables[59]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_BOOL, 0, false, false, false, false, "repeated_bool", 17, &msgs[1], NULL, 68, 22, {0},&reftables[60], &reftables[61]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_BYTES, 0, false, false, false, false, "repeated_bytes", 16, &msgs[1], NULL, 63, 21, {0},&reftables[62], &reftables[63]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_ENUM, 0, false, false, false, false, "repeated_enum", 19, &msgs[1], (const upb_def*)(&enums[0]), 71, 23, {0},&reftables[64], &reftables[65]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "repeated_int32", 11, &msgs[1], NULL, 46, 16, {0},&reftables[66], &reftables[67]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "repeated_int64", 12, &msgs[1], NULL, 49, 17, {0},&reftables[68], &reftables[69]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "repeated_msg", 18, &msgs[1], (const upb_def*)(&msgs[0]), 13, 1, {0},&reftables[70], &reftables[71]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "repeated_string", 15, &msgs[1], NULL, 58, 20, {0},&reftables[72], &reftables[73]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_UINT32, UPB_INTFMT_VARIABLE, false, false, false, false, "repeated_uint32", 13, &msgs[1], NULL, 52, 18, {0},&reftables[74], &reftables[75]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "repeated_uint64", 14, &msgs[1], NULL, 55, 19, {0},&reftables[76], &reftables[77]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[6], (const upb_def*)(&msgs[0]), 3, 0, {0},&reftables[78], &reftables[79]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "value", 2, &msgs[7], NULL, 5, 1, {0},&reftables[80], &reftables[81]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "value", 2, &msgs[5], NULL, 5, 1, {0},&reftables[82], &reftables[83]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "value", 2, &msgs[2], NULL, 3, 1, {0},&reftables[84], &reftables[85]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "value", 2, &msgs[4], NULL, 5, 1, {0},&reftables[86], &reftables[87]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "value", 2, &msgs[3], NULL, 3, 1, {0},&reftables[88], &reftables[89]),
+};
+
+static const upb_enumdef enums[1] = {
+ UPB_ENUMDEF_INIT("upb.test.json.MyEnum", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[60]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[46], 3, 3), 0, &reftables[90], &reftables[91]),
+};
+
+static const upb_tabent strentries[64] = {
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "foo"), UPB_TABVALUE_PTR_INIT(&fields[0]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "repeated_enum"), UPB_TABVALUE_PTR_INIT(&fields[24]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "optional_enum"), UPB_TABVALUE_PTR_INIT(&fields[15]), &strentries[31]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "optional_int32"), UPB_TABVALUE_PTR_INIT(&fields[16]), NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "repeated_bool"), UPB_TABVALUE_PTR_INIT(&fields[22]), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "repeated_bytes"), UPB_TABVALUE_PTR_INIT(&fields[23]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "optional_int64"), UPB_TABVALUE_PTR_INIT(&fields[17]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "optional_string"), UPB_TABVALUE_PTR_INIT(&fields[19]), NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "optional_bool"), UPB_TABVALUE_PTR_INIT(&fields[13]), &strentries[30]},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "map_int32_string"), UPB_TABVALUE_PTR_INIT(&fields[8]), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "optional_bytes"), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optional_msg"), UPB_TABVALUE_PTR_INIT(&fields[18]), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "repeated_int32"), UPB_TABVALUE_PTR_INIT(&fields[25]), &strentries[35]},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "repeated_uint32"), UPB_TABVALUE_PTR_INIT(&fields[29]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "map_bool_string"), UPB_TABVALUE_PTR_INIT(&fields[7]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "optional_uint64"), UPB_TABVALUE_PTR_INIT(&fields[21]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "optional_uint32"), UPB_TABVALUE_PTR_INIT(&fields[20]), &strentries[32]},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "map_string_bool"), UPB_TABVALUE_PTR_INIT(&fields[9]), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "repeated_int64"), UPB_TABVALUE_PTR_INIT(&fields[26]), &strentries[34]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "map_string_msg"), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "map_string_int32"), UPB_TABVALUE_PTR_INIT(&fields[10]), NULL},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "map_string_string"), UPB_TABVALUE_PTR_INIT(&fields[12]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "repeated_uint64"), UPB_TABVALUE_PTR_INIT(&fields[30]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "repeated_msg"), UPB_TABVALUE_PTR_INIT(&fields[27]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "repeated_string"), UPB_TABVALUE_PTR_INIT(&fields[28]), NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "key"), UPB_TABVALUE_PTR_INIT(&fields[3]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[34]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "key"), UPB_TABVALUE_PTR_INIT(&fields[2]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[36]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "key"), UPB_TABVALUE_PTR_INIT(&fields[5]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[35]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "key"), UPB_TABVALUE_PTR_INIT(&fields[4]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[33]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "key"), UPB_TABVALUE_PTR_INIT(&fields[6]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[31]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "key"), UPB_TABVALUE_PTR_INIT(&fields[1]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[32]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\001", "\000", "\000", "\000", "A"), UPB_TABVALUE_INT_INIT(0), NULL},
+ {UPB_TABKEY_STR("\001", "\000", "\000", "\000", "B"), UPB_TABVALUE_INT_INIT(1), &strentries[63]},
+ {UPB_TABKEY_STR("\001", "\000", "\000", "\000", "C"), UPB_TABVALUE_INT_INIT(2), NULL},
+};
+
+static const upb_tabval arrays[49] = {
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[0]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[16]),
+ UPB_TABVALUE_PTR_INIT(&fields[17]),
+ UPB_TABVALUE_PTR_INIT(&fields[20]),
+ UPB_TABVALUE_PTR_INIT(&fields[21]),
+ UPB_TABVALUE_PTR_INIT(&fields[19]),
+ UPB_TABVALUE_PTR_INIT(&fields[14]),
+ UPB_TABVALUE_PTR_INIT(&fields[13]),
+ UPB_TABVALUE_PTR_INIT(&fields[18]),
+ UPB_TABVALUE_PTR_INIT(&fields[15]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[25]),
+ UPB_TABVALUE_PTR_INIT(&fields[26]),
+ UPB_TABVALUE_PTR_INIT(&fields[29]),
+ UPB_TABVALUE_PTR_INIT(&fields[30]),
+ UPB_TABVALUE_PTR_INIT(&fields[28]),
+ UPB_TABVALUE_PTR_INIT(&fields[23]),
+ UPB_TABVALUE_PTR_INIT(&fields[22]),
+ UPB_TABVALUE_PTR_INIT(&fields[27]),
+ UPB_TABVALUE_PTR_INIT(&fields[24]),
+ UPB_TABVALUE_PTR_INIT(&fields[12]),
+ UPB_TABVALUE_PTR_INIT(&fields[8]),
+ UPB_TABVALUE_PTR_INIT(&fields[7]),
+ UPB_TABVALUE_PTR_INIT(&fields[10]),
+ UPB_TABVALUE_PTR_INIT(&fields[9]),
+ UPB_TABVALUE_PTR_INIT(&fields[11]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[3]),
+ UPB_TABVALUE_PTR_INIT(&fields[34]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[2]),
+ UPB_TABVALUE_PTR_INIT(&fields[36]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[5]),
+ UPB_TABVALUE_PTR_INIT(&fields[35]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[4]),
+ UPB_TABVALUE_PTR_INIT(&fields[33]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[6]),
+ UPB_TABVALUE_PTR_INIT(&fields[31]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[1]),
+ UPB_TABVALUE_PTR_INIT(&fields[32]),
+ UPB_TABVALUE_PTR_INIT("A"),
+ UPB_TABVALUE_PTR_INIT("B"),
+ UPB_TABVALUE_PTR_INIT("C"),
+};
+
+#ifdef UPB_DEBUG_REFS
+static upb_inttable reftables[92] = {
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+};
+#endif
+
+static const upb_msgdef *refm(const upb_msgdef *m, const void *owner) {
+ upb_msgdef_ref(m, owner);
+ return m;
+}
+
+static const upb_enumdef *refe(const upb_enumdef *e, const void *owner) {
+ upb_enumdef_ref(e, owner);
+ return e;
+}
+
+/* Public API. */
+const upb_msgdef *upbdefs_upb_test_json_SubMessage_get(const void *owner) { return refm(&msgs[0], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_get(const void *owner) { return refm(&msgs[1], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_get(const void *owner) { return refm(&msgs[2], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_get(const void *owner) { return refm(&msgs[3], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_get(const void *owner) { return refm(&msgs[4], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_get(const void *owner) { return refm(&msgs[5], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_get(const void *owner) { return refm(&msgs[6], owner); }
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringStringEntry_get(const void *owner) { return refm(&msgs[7], owner); }
+
+const upb_enumdef *upbdefs_upb_test_json_MyEnum_get(const void *owner) { return refe(&enums[0], owner); }
diff --git a/tests/json/test.upbdefs.h b/tests/json/test.upbdefs.h
new file mode 100644
index 0000000..d3c23b3
--- /dev/null
+++ b/tests/json/test.upbdefs.h
@@ -0,0 +1,246 @@
+/* This file contains accessors for a set of compiled-in defs.
+ * Note that unlike Google's protobuf, it does *not* define
+ * generated classes or any other kind of data structure for
+ * actually storing protobufs. It only contains *defs* which
+ * let you reflect over a protobuf *schema*.
+ */
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * tests/json/test.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+#ifndef TESTS_JSON_TEST_PROTO_UPB_H_
+#define TESTS_JSON_TEST_PROTO_UPB_H_
+
+#include "upb/def.h"
+
+UPB_BEGIN_EXTERN_C
+
+/* Enums */
+
+typedef enum {
+ upb_test_json_A = 0,
+ upb_test_json_B = 1,
+ upb_test_json_C = 2
+} upb_test_json_MyEnum;
+
+/* MessageDefs: call these functions to get a ref to a msgdef. */
+const upb_msgdef *upbdefs_upb_test_json_SubMessage_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_get(const void *owner);
+const upb_msgdef *upbdefs_upb_test_json_TestMessage_MapStringStringEntry_get(const void *owner);
+
+/* EnumDefs: call these functions to get a ref to an enumdef. */
+const upb_enumdef *upbdefs_upb_test_json_MyEnum_get(const void *owner);
+
+/* Functions to test whether this message is of a certain type. */
+UPB_INLINE bool upbdefs_upb_test_json_SubMessage_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.SubMessage") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage.MapBoolStringEntry") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage.MapInt32StringEntry") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage.MapStringBoolEntry") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage.MapStringInt32Entry") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage.MapStringMsgEntry") == 0;
+}
+UPB_INLINE bool upbdefs_upb_test_json_TestMessage_MapStringStringEntry_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "upb.test.json.TestMessage.MapStringStringEntry") == 0;
+}
+
+/* Functions to test whether this enum is of a certain type. */
+UPB_INLINE bool upbdefs_upb_test_json_MyEnum_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "upb.test.json.MyEnum") == 0;
+}
+
+
+/* Functions to get a fielddef from a msgdef reference. */
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_SubMessage_f_foo(const upb_msgdef *m) { assert(upbdefs_upb_test_json_SubMessage_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_f_key(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_f_value(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_f_key(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_f_value(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_f_key(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_f_value(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_f_key(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_f_value(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_f_key(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_f_value(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringStringEntry_f_key(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringStringEntry_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_MapStringStringEntry_f_value(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_MapStringStringEntry_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_map_bool_string(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 22); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_map_int32_string(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 21); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_map_string_bool(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 24); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_map_string_int32(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 23); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_map_string_msg(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 25); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_map_string_string(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 20); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_bool(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_bytes(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_enum(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_int32(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_int64(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_msg(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_string(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_uint32(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_optional_uint64(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_bool(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 17); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_bytes(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 16); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_enum(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 19); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_int32(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 11); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_int64(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 12); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_msg(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 18); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_string(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 15); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_uint32(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 13); }
+UPB_INLINE const upb_fielddef *upbdefs_upb_test_json_TestMessage_f_repeated_uint64(const upb_msgdef *m) { assert(upbdefs_upb_test_json_TestMessage_is(m)); return upb_msgdef_itof(m, 14); }
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upbdefs {
+namespace upb {
+namespace test {
+namespace json {
+
+class MyEnum : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ MyEnum(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ assert(upbdefs_upb_test_json_MyEnum_is(e));
+ }
+ static MyEnum get() {
+ const ::upb::EnumDef* e = upbdefs_upb_test_json_MyEnum_get(&e);
+ return MyEnum(e, &e);
+ }
+};
+
+class SubMessage : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ SubMessage(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_SubMessage_is(m));
+ }
+
+ static SubMessage get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_SubMessage_get(&m);
+ return SubMessage(m, &m);
+ }
+};
+
+class TestMessage : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ TestMessage(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_is(m));
+ }
+
+ static TestMessage get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_get(&m);
+ return TestMessage(m, &m);
+ }
+
+ class MapBoolStringEntry : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MapBoolStringEntry(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_is(m));
+ }
+
+ static MapBoolStringEntry get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_MapBoolStringEntry_get(&m);
+ return MapBoolStringEntry(m, &m);
+ }
+ };
+
+ class MapInt32StringEntry : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MapInt32StringEntry(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_is(m));
+ }
+
+ static MapInt32StringEntry get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_MapInt32StringEntry_get(&m);
+ return MapInt32StringEntry(m, &m);
+ }
+ };
+
+ class MapStringBoolEntry : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MapStringBoolEntry(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_is(m));
+ }
+
+ static MapStringBoolEntry get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_MapStringBoolEntry_get(&m);
+ return MapStringBoolEntry(m, &m);
+ }
+ };
+
+ class MapStringInt32Entry : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MapStringInt32Entry(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_is(m));
+ }
+
+ static MapStringInt32Entry get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_MapStringInt32Entry_get(&m);
+ return MapStringInt32Entry(m, &m);
+ }
+ };
+
+ class MapStringMsgEntry : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MapStringMsgEntry(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_is(m));
+ }
+
+ static MapStringMsgEntry get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_MapStringMsgEntry_get(&m);
+ return MapStringMsgEntry(m, &m);
+ }
+ };
+
+ class MapStringStringEntry : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MapStringStringEntry(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ assert(upbdefs_upb_test_json_TestMessage_MapStringStringEntry_is(m));
+ }
+
+ static MapStringStringEntry get() {
+ const ::upb::MessageDef* m = upbdefs_upb_test_json_TestMessage_MapStringStringEntry_get(&m);
+ return MapStringStringEntry(m, &m);
+ }
+ };
+};
+
+} /* namespace json */
+} /* namespace test */
+} /* namespace upb */
+} /* namespace upbdefs */
+
+#endif /* __cplusplus */
+
+#endif /* TESTS_JSON_TEST_PROTO_UPB_H_ */
diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc
index 6874131..b7548fe 100644
--- a/tests/json/test_json.cc
+++ b/tests/json/test_json.cc
@@ -3,12 +3,12 @@
* A set of tests for JSON parsing and serialization.
*/
+#include "tests/json/test.upbdefs.h"
#include "tests/test_util.h"
#include "tests/upb_test.h"
#include "upb/handlers.h"
-#include "upb/symtab.h"
-#include "upb/json/printer.h"
#include "upb/json/parser.h"
+#include "upb/json/printer.h"
#include "upb/upb.h"
#include <string>
@@ -135,147 +135,6 @@ static TestCase kTestRoundtripMessagesPreserve[] = {
TEST_SENTINEL
};
-static void AddField(upb::MessageDef* message,
- int number,
- const char* name,
- upb_fieldtype_t type,
- bool is_repeated,
- const upb::Def* subdef = NULL) {
- upb::reffed_ptr<upb::FieldDef> field(upb::FieldDef::New());
- upb::Status st;
- field->set_name(name, &st);
- field->set_type(type);
- field->set_label(is_repeated ? UPB_LABEL_REPEATED : UPB_LABEL_OPTIONAL);
- field->set_number(number, &st);
- if (subdef) {
- field->set_subdef(subdef, &st);
- }
- message->AddField(field, &st);
-}
-
-static const upb::MessageDef* BuildTestMessage(
- upb::reffed_ptr<upb::SymbolTable> symtab) {
- upb::Status st;
-
- // Create SubMessage.
- upb::reffed_ptr<upb::MessageDef> submsg(upb::MessageDef::New());
- submsg->set_full_name("SubMessage", &st);
- AddField(submsg.get(), 1, "foo", UPB_TYPE_INT32, false);
-
- // Create MapEntryStringString.
- upb::reffed_ptr<upb::MessageDef> mapentry_string_string(
- upb::MessageDef::New());
- mapentry_string_string->set_full_name("MapEntry_String_String", &st);
- mapentry_string_string->setmapentry(true);
- AddField(mapentry_string_string.get(), 1, "key", UPB_TYPE_STRING, false);
- AddField(mapentry_string_string.get(), 2, "value", UPB_TYPE_STRING, false);
-
- // Create MapEntryInt32String.
- upb::reffed_ptr<upb::MessageDef> mapentry_int32_string(
- upb::MessageDef::New());
- mapentry_int32_string->set_full_name("MapEntry_Int32_String", &st);
- mapentry_int32_string->setmapentry(true);
- AddField(mapentry_int32_string.get(), 1, "key", UPB_TYPE_INT32, false);
- AddField(mapentry_int32_string.get(), 2, "value", UPB_TYPE_STRING, false);
-
- // Create MapEntryBoolString.
- upb::reffed_ptr<upb::MessageDef> mapentry_bool_string(
- upb::MessageDef::New());
- mapentry_bool_string->set_full_name("MapEntry_Bool_String", &st);
- mapentry_bool_string->setmapentry(true);
- AddField(mapentry_bool_string.get(), 1, "key", UPB_TYPE_BOOL, false);
- AddField(mapentry_bool_string.get(), 2, "value", UPB_TYPE_STRING, false);
-
- // Create MapEntryStringInt32.
- upb::reffed_ptr<upb::MessageDef> mapentry_string_int32(
- upb::MessageDef::New());
- mapentry_string_int32->set_full_name("MapEntry_String_Int32", &st);
- mapentry_string_int32->setmapentry(true);
- AddField(mapentry_string_int32.get(), 1, "key", UPB_TYPE_STRING, false);
- AddField(mapentry_string_int32.get(), 2, "value", UPB_TYPE_INT32, false);
-
- // Create MapEntryStringBool.
- upb::reffed_ptr<upb::MessageDef> mapentry_string_bool(upb::MessageDef::New());
- mapentry_string_bool->set_full_name("MapEntry_String_Bool", &st);
- mapentry_string_bool->setmapentry(true);
- AddField(mapentry_string_bool.get(), 1, "key", UPB_TYPE_STRING, false);
- AddField(mapentry_string_bool.get(), 2, "value", UPB_TYPE_BOOL, false);
-
- // Create MapEntryStringMessage.
- upb::reffed_ptr<upb::MessageDef> mapentry_string_msg(upb::MessageDef::New());
- mapentry_string_msg->set_full_name("MapEntry_String_Message", &st);
- mapentry_string_msg->setmapentry(true);
- AddField(mapentry_string_msg.get(), 1, "key", UPB_TYPE_STRING, false);
- AddField(mapentry_string_msg.get(), 2, "value", UPB_TYPE_MESSAGE, false,
- upb::upcast(submsg.get()));
-
- // Create MyEnum.
- upb::reffed_ptr<upb::EnumDef> myenum(upb::EnumDef::New());
- myenum->set_full_name("MyEnum", &st);
- myenum->AddValue("A", 0, &st);
- myenum->AddValue("B", 1, &st);
- myenum->AddValue("C", 2, &st);
-
- // Create TestMessage.
- upb::reffed_ptr<upb::MessageDef> md(upb::MessageDef::New());
- md->set_full_name("TestMessage", &st);
-
- AddField(md.get(), 1, "optional_int32", UPB_TYPE_INT32, false);
- AddField(md.get(), 2, "optional_int64", UPB_TYPE_INT64, false);
- AddField(md.get(), 3, "optional_uint32", UPB_TYPE_UINT32, false);
- AddField(md.get(), 4, "optional_uint64", UPB_TYPE_UINT64, false);
- AddField(md.get(), 5, "optional_string", UPB_TYPE_STRING, false);
- AddField(md.get(), 6, "optional_bytes", UPB_TYPE_BYTES, false);
- AddField(md.get(), 7, "optional_bool" , UPB_TYPE_BOOL, false);
- AddField(md.get(), 8, "optional_msg" , UPB_TYPE_MESSAGE, false,
- upb::upcast(submsg.get()));
- AddField(md.get(), 9, "optional_enum", UPB_TYPE_ENUM, false,
- upb::upcast(myenum.get()));
-
- AddField(md.get(), 11, "repeated_int32", UPB_TYPE_INT32, true);
- AddField(md.get(), 12, "repeated_int64", UPB_TYPE_INT64, true);
- AddField(md.get(), 13, "repeated_uint32", UPB_TYPE_UINT32, true);
- AddField(md.get(), 14, "repeated_uint64", UPB_TYPE_UINT64, true);
- AddField(md.get(), 15, "repeated_string", UPB_TYPE_STRING, true);
- AddField(md.get(), 16, "repeated_bytes", UPB_TYPE_BYTES, true);
- AddField(md.get(), 17, "repeated_bool" , UPB_TYPE_BOOL, true);
- AddField(md.get(), 18, "repeated_msg" , UPB_TYPE_MESSAGE, true,
- upb::upcast(submsg.get()));
- AddField(md.get(), 19, "optional_enum", UPB_TYPE_ENUM, true,
- upb::upcast(myenum.get()));
-
- AddField(md.get(), 20, "map_string_string", UPB_TYPE_MESSAGE, true,
- upb::upcast(mapentry_string_string.get()));
- AddField(md.get(), 21, "map_int32_string", UPB_TYPE_MESSAGE, true,
- upb::upcast(mapentry_int32_string.get()));
- AddField(md.get(), 22, "map_bool_string", UPB_TYPE_MESSAGE, true,
- upb::upcast(mapentry_bool_string.get()));
- AddField(md.get(), 23, "map_string_int32", UPB_TYPE_MESSAGE, true,
- upb::upcast(mapentry_string_int32.get()));
- AddField(md.get(), 24, "map_string_bool", UPB_TYPE_MESSAGE, true,
- upb::upcast(mapentry_string_bool.get()));
- AddField(md.get(), 25, "map_string_msg", UPB_TYPE_MESSAGE, true,
- upb::upcast(mapentry_string_msg.get()));
-
- // Add both to our symtab.
- upb::Def* defs[9] = {
- upb::upcast(submsg.ReleaseTo(&defs)),
- upb::upcast(myenum.ReleaseTo(&defs)),
- upb::upcast(md.ReleaseTo(&defs)),
- upb::upcast(mapentry_string_string.ReleaseTo(&defs)),
- upb::upcast(mapentry_int32_string.ReleaseTo(&defs)),
- upb::upcast(mapentry_bool_string.ReleaseTo(&defs)),
- upb::upcast(mapentry_string_int32.ReleaseTo(&defs)),
- upb::upcast(mapentry_string_bool.ReleaseTo(&defs)),
- upb::upcast(mapentry_string_msg.ReleaseTo(&defs)),
- };
- symtab->Add(defs, 9, &defs, &st);
- ASSERT(st.ok());
-
- // Return TestMessage.
- return symtab->LookupMessage("TestMessage");
-}
-
class StringSink {
public:
StringSink() {
@@ -343,12 +202,12 @@ void test_json_roundtrip_message(const char* json_src,
// Starts with a message in JSON format, parses and directly serializes again,
// and compares the result.
void test_json_roundtrip() {
- upb::reffed_ptr<upb::SymbolTable> symtab(upb::SymbolTable::New());
- const upb::MessageDef* md = BuildTestMessage(symtab.get());
+ upb::reffed_ptr<const upb::MessageDef> md(
+ upbdefs::upb::test::json::TestMessage::get());
upb::reffed_ptr<const upb::Handlers> serialize_handlers(
- upb::json::Printer::NewHandlers(md, false));
+ upb::json::Printer::NewHandlers(md.get(), false));
upb::reffed_ptr<const upb::json::ParserMethod> parser_method(
- upb::json::ParserMethod::New(md));
+ upb::json::ParserMethod::New(md.get()));
for (const TestCase* test_case = kTestRoundtripMessages;
test_case->input != NULL; test_case++) {
@@ -364,7 +223,7 @@ void test_json_roundtrip() {
}
}
- serialize_handlers = upb::json::Printer::NewHandlers(md, true);
+ serialize_handlers = upb::json::Printer::NewHandlers(md.get(), true);
for (const TestCase* test_case = kTestRoundtripMessagesPreserve;
test_case->input != NULL; test_case++) {
diff --git a/tools/dump_cinit.lua b/tools/dump_cinit.lua
index 17be8d9..e01e150 100644
--- a/tools/dump_cinit.lua
+++ b/tools/dump_cinit.lua
@@ -292,8 +292,12 @@ local function gettables(def)
end
end
-local function emit_file_warning(append)
- append('/* This file was generated by upbc (the upb compiler).\n')
+local function emit_file_warning(filedef, append)
+ append('/* This file was generated by upbc (the upb compiler) from the input\n')
+ append(' * file:\n')
+ append(' *\n')
+ append(' * %s\n', filedef:name())
+ append(' *\n')
append(' * Do not edit -- your changes will be discarded when the file is\n')
append(' * regenerated. */\n\n')
end
@@ -402,7 +406,7 @@ local function dump_defs_c(filedef, append)
end
-- Emit forward declarations.
- emit_file_warning(append)
+ emit_file_warning(filedef, append)
append('#include <assert.h>\n\n')
append('#include "upb/def.h"\n')
append('#include "upb/structdefs.int.h"\n\n')
@@ -432,13 +436,15 @@ local function dump_defs_c(filedef, append)
local tables = gettables(m)
-- UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof,
-- refs, ref2s)
- append(' UPB_MSGDEF_INIT("%s", %d, %d, %s, %s,' ..
- '&reftables[%d], &reftables[%d]),\n',
+ append(' UPB_MSGDEF_INIT("%s", %d, %d, %s, %s, %s, %s,' ..
+ ' &reftables[%d], &reftables[%d]),\n',
m:full_name(),
upbtable.msgdef_selector_count(m),
upbtable.msgdef_submsg_field_count(m),
dumper:inttable(tables.int),
dumper:strtable(tables.str),
+ boolstr(m:_map_entry()),
+ const(m, "syntax"),
reftable, reftable + 1)
reftable = reftable + 2
end
@@ -627,17 +633,17 @@ local print_classes
local function print_message(def, map, indent, append)
append("\n")
- append("%sclass %s : public upb::reffed_ptr<const upb::MessageDef> {\n",
+ append("%sclass %s : public ::upb::reffed_ptr<const ::upb::MessageDef> {\n",
indent, def:name())
append("%s public:\n", indent)
- append("%s %s(const upb::MessageDef* m, const void *ref_donor = NULL)\n",
+ append("%s %s(const ::upb::MessageDef* m, const void *ref_donor = NULL)\n",
indent, def:name())
append("%s : reffed_ptr(m, ref_donor) {\n", indent)
append("%s assert(upbdefs_%s_is(m));\n", indent, to_cident(def:full_name()))
append("%s }\n", indent)
append("\n")
append("%s static %s get() {\n", indent, def:name())
- append("%s const upb::MessageDef* m = upbdefs_%s_get(&m);\n", indent, to_cident(def:full_name()))
+ append("%s const ::upb::MessageDef* m = upbdefs_%s_get(&m);\n", indent, to_cident(def:full_name()))
append("%s return %s(m, &m);\n", indent, def:name())
append("%s }\n", indent)
-- TODO(haberman): add fields
@@ -647,16 +653,16 @@ end
local function print_enum(def, indent, append)
append("\n")
- append("%sclass %s : public upb::reffed_ptr<const upb::EnumDef> {\n",
+ append("%sclass %s : public ::upb::reffed_ptr<const ::upb::EnumDef> {\n",
indent, def:name())
append("%s public:\n", indent)
- append("%s %s(const upb::EnumDef* e, const void *ref_donor = NULL)\n",
+ append("%s %s(const ::upb::EnumDef* e, const void *ref_donor = NULL)\n",
indent, def:name())
append("%s : reffed_ptr(e, ref_donor) {\n", indent)
append("%s assert(upbdefs_%s_is(e));\n", indent, to_cident(def:full_name()))
append("%s }\n", indent)
append("%s static %s get() {\n", indent, def:name())
- append("%s const upb::EnumDef* e = upbdefs_%s_get(&e);\n", indent, to_cident(def:full_name()))
+ append("%s const ::upb::EnumDef* e = upbdefs_%s_get(&e);\n", indent, to_cident(def:full_name()))
append("%s return %s(e, &e);\n", indent, def:name())
append("%s }\n", indent)
append("%s};\n", indent)
@@ -686,7 +692,7 @@ local function dump_defs_h(file, append, linktab)
append(" * actually storing protobufs. It only contains *defs* which\n")
append(" * let you reflect over a protobuf *schema*.\n")
append(" */\n")
- emit_file_warning(append)
+ emit_file_warning(file, append)
append('#ifndef %s_UPB_H_\n', basename_preproc)
append('#define %s_UPB_H_\n\n', basename_preproc)
append('#include "upb/def.h"\n\n')
diff --git a/travis.sh b/travis.sh
index 0b7d48a..02fede8 100755
--- a/travis.sh
+++ b/travis.sh
@@ -73,6 +73,12 @@ lua_script() {
genfiles_install() {
sudo apt-get update -qq
sudo apt-get install lua5.2 liblua5.2-dev
+
+ # Need a recent version of protoc to compile proto3 files.
+ wget https://github.com/google/protobuf/releases/download/v3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.zip
+ unzip protoc-3.0.0-beta-2-linux-x86_64.zip
+ export PATH=.:$PATH
+ protoc --version || true
}
genfiles_script() {
# Avoid regenerating descriptor.pb, since its output can vary based on the
diff --git a/upb/bindings/lua/upb.c b/upb/bindings/lua/upb.c
index 531967c..7a66180 100644
--- a/upb/bindings/lua/upb.c
+++ b/upb/bindings/lua/upb.c
@@ -959,6 +959,18 @@ static int lupb_msgdef_fields(lua_State *L) {
return 1;
}
+static int lupb_msgdef_mapentry(lua_State *L) {
+ const upb_msgdef *m = lupb_msgdef_check(L, 1);
+ lua_pushboolean(L, upb_msgdef_mapentry(m));
+ return 1;
+}
+
+static int lupb_msgdef_syntax(lua_State *L) {
+ const upb_msgdef *m = lupb_msgdef_check(L, 1);
+ lua_pushinteger(L, upb_msgdef_syntax(m));
+ return 1;
+}
+
static const struct luaL_Reg lupb_msgdef_mm[] = {
{"__gc", lupb_msgdef_gc},
{"__len", lupb_msgdef_len},
@@ -970,6 +982,8 @@ static const struct luaL_Reg lupb_msgdef_m[] = {
{"add", lupb_msgdef_add},
{"field", lupb_msgdef_field},
{"fields", lupb_msgdef_fields},
+ {"syntax", lupb_msgdef_syntax},
+ {"_map_entry", lupb_msgdef_mapentry},
{NULL, NULL}
};
@@ -2013,5 +2027,8 @@ int luaopen_upb_c(lua_State *L) {
lupb_setfieldi(L, "HANDLER_STARTSEQ", UPB_HANDLER_STARTSEQ);
lupb_setfieldi(L, "HANDLER_ENDSEQ", UPB_HANDLER_ENDSEQ);
+ lupb_setfieldi(L, "SYNTAX_PROTO2", UPB_SYNTAX_PROTO2);
+ lupb_setfieldi(L, "SYNTAX_PROTO3", UPB_SYNTAX_PROTO3);
+
return 1; /* Return package table. */
}
diff --git a/upb/def.c b/upb/def.c
index 1e51c97..0febf47 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -1461,6 +1461,19 @@ bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname,
return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s);
}
+bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax) {
+ if (syntax != UPB_SYNTAX_PROTO2 && syntax != UPB_SYNTAX_PROTO3) {
+ return false;
+ }
+
+ m->syntax = syntax;
+ return true;
+}
+
+upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) {
+ return m->syntax;
+}
+
/* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error
* on status |s| and return false if not. */
static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f,
diff --git a/upb/def.h b/upb/def.h
index d4808a6..87e1766 100644
--- a/upb/def.h
+++ b/upb/def.h
@@ -272,6 +272,11 @@ typedef enum {
UPB_DESCRIPTOR_TYPE_SINT64 = 18
} upb_descriptortype_t;
+typedef enum {
+ UPB_SYNTAX_PROTO2 = 2,
+ UPB_SYNTAX_PROTO3 = 3
+} upb_syntax_t;
+
/* Maximum field number allowed for FieldDefs. This is an inherent limit of the
* protobuf wire format. */
#define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
@@ -721,6 +726,11 @@ class upb::MessageDef {
bool AddOneof(OneofDef* o, Status* s);
bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s);
+ upb_syntax_t syntax() const;
+
+ /* Returns false if we don't support this syntax value. */
+ bool set_syntax(upb_syntax_t syntax);
+
/* Set this to false to indicate that primitive fields should not have
* explicit presence information associated with them. This will affect all
* fields added to this message. Defaults to true. */
@@ -913,6 +923,7 @@ bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status);
const char *upb_msgdef_fullname(const upb_msgdef *m);
const char *upb_msgdef_name(const upb_msgdef *m);
+upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s);
upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner);
@@ -963,6 +974,7 @@ UPB_INLINE upb_oneofdef *upb_msgdef_ntoo_mutable(upb_msgdef *m,
void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry);
bool upb_msgdef_mapentry(const upb_msgdef *m);
+bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
/* Well-known field tag numbers for map-entry messages. */
#define UPB_MAPENTRY_KEY 1
@@ -1284,11 +1296,6 @@ UPB_END_EXTERN_C
/* upb::FileDef ***************************************************************/
-typedef enum {
- UPB_SYNTAX_PROTO2 = 2,
- UPB_SYNTAX_PROTO3 = 3
-} upb_syntax_t;
-
#ifdef __cplusplus
/* Class that represents a .proto file with some things defined in it.
@@ -1651,12 +1658,18 @@ inline const char *MessageDef::full_name() const {
inline const char *MessageDef::name() const {
return upb_msgdef_name(this);
}
+inline upb_syntax_t MessageDef::syntax() const {
+ return upb_msgdef_syntax(this);
+}
inline bool MessageDef::set_full_name(const char* fullname, Status* s) {
return upb_msgdef_setfullname(this, fullname, s);
}
inline bool MessageDef::set_full_name(const std::string& fullname, Status* s) {
return upb_msgdef_setfullname(this, upb_safecstr(fullname), s);
}
+inline bool MessageDef::set_syntax(upb_syntax_t syntax) {
+ return upb_msgdef_setsyntax(this, syntax);
+}
inline bool MessageDef::Freeze(Status* status) {
return upb_msgdef_freeze(this, status);
}
diff --git a/upb/descriptor/descriptor.pb b/upb/descriptor/descriptor.pb
index 3b07163..d61554b 100644
--- a/upb/descriptor/descriptor.pb
+++ b/upb/descriptor/descriptor.pb
Binary files differ
diff --git a/upb/descriptor/descriptor.upbdefs.c b/upb/descriptor/descriptor.upbdefs.c
index dec2b14..d27adf4 100644
--- a/upb/descriptor/descriptor.upbdefs.c
+++ b/upb/descriptor/descriptor.upbdefs.c
@@ -1,4 +1,8 @@
-/* This file was generated by upbc (the upb compiler).
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * upb/descriptor/descriptor.proto
+ *
* Do not edit -- your changes will be discarded when the file is
* regenerated. */
@@ -19,28 +23,28 @@ static upb_inttable reftables[264];
#endif
static const upb_msgdef msgs[22] = {
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 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]),&reftables[0], &reftables[1]),
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 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]),&reftables[2], &reftables[3]),
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 4, 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]),&reftables[4], &reftables[5]),
- UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 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]),&reftables[6], &reftables[7]),
- UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 8, 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]),&reftables[8], &reftables[9]),
- UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 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]),&reftables[10], &reftables[11]),
- UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 7, 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]),&reftables[12], &reftables[13]),
- UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 23, 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]),&reftables[14], &reftables[15]),
- UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 12, 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]),&reftables[16], &reftables[17]),
- UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 42, 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]),&reftables[18], &reftables[19]),
- UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 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]),&reftables[20], &reftables[21]),
- UPB_MSGDEF_INIT("google.protobuf.FileOptions", 31, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 39, 15), UPB_STRTABLE_INIT(16, 31, UPB_CTYPE_PTR, 5, &strentries[92]),&reftables[22], &reftables[23]),
- UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[107], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]),&reftables[24], &reftables[25]),
- UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 15, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[115], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]),&reftables[26], &reftables[27]),
- UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[122], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]),&reftables[28], &reftables[29]),
- UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[123], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]),&reftables[30], &reftables[31]),
- UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[125], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]),&reftables[32], &reftables[33]),
- UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[129], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]),&reftables[34], &reftables[35]),
- UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[130], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]),&reftables[36], &reftables[37]),
- UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 19, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[132], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]),&reftables[38], &reftables[39]),
- UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[139], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]),&reftables[40], &reftables[41]),
- UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[148], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]),&reftables[42], &reftables[43]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 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.ExtensionRange", 4, 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.ReservedRange", 4, 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.EnumDescriptorProto", 11, 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.EnumOptions", 8, 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.EnumValueDescriptorProto", 8, 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.EnumValueOptions", 7, 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.FieldDescriptorProto", 23, 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.FieldOptions", 12, 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.FileDescriptorProto", 42, 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.FileDescriptorSet", 6, 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.FileOptions", 31, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 39, 15), UPB_STRTABLE_INIT(16, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]),
+ UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[107], 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.MethodDescriptorProto", 15, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[115], 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.MethodOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[122], 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.OneofDescriptorProto", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[123], 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.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[125], 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.ServiceOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[129], 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.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[130], 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.Location", 19, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[132], 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.UninterpretedOption", 18, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[139], 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.NamePart", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[148], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]),
};
static const upb_fielddef fields[105] = {
diff --git a/upb/descriptor/descriptor.upbdefs.h b/upb/descriptor/descriptor.upbdefs.h
index 6d9b5c4..d8a22ca 100644
--- a/upb/descriptor/descriptor.upbdefs.h
+++ b/upb/descriptor/descriptor.upbdefs.h
@@ -4,7 +4,11 @@
* actually storing protobufs. It only contains *defs* which
* let you reflect over a protobuf *schema*.
*/
-/* This file was generated by upbc (the upb compiler).
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * upb/descriptor/descriptor.proto
+ *
* Do not edit -- your changes will be discarded when the file is
* regenerated. */
@@ -294,347 +298,347 @@ namespace upbdefs {
namespace google {
namespace protobuf {
-class DescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class DescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- DescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ DescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_DescriptorProto_is(m));
}
static DescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_get(&m);
return DescriptorProto(m, &m);
}
- class ExtensionRange : public upb::reffed_ptr<const upb::MessageDef> {
+ class ExtensionRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- ExtensionRange(const upb::MessageDef* m, const void *ref_donor = NULL)
+ ExtensionRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m));
}
static ExtensionRange get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(&m);
return ExtensionRange(m, &m);
}
};
- class ReservedRange : public upb::reffed_ptr<const upb::MessageDef> {
+ class ReservedRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- ReservedRange(const upb::MessageDef* m, const void *ref_donor = NULL)
+ ReservedRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m));
}
static ReservedRange get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(&m);
return ReservedRange(m, &m);
}
};
};
-class EnumDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class EnumDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- EnumDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ EnumDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_EnumDescriptorProto_is(m));
}
static EnumDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_EnumDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumDescriptorProto_get(&m);
return EnumDescriptorProto(m, &m);
}
};
-class EnumOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class EnumOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- EnumOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ EnumOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_EnumOptions_is(m));
}
static EnumOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_EnumOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumOptions_get(&m);
return EnumOptions(m, &m);
}
};
-class EnumValueDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class EnumValueDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- EnumValueDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ EnumValueDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m));
}
static EnumValueDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_EnumValueDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueDescriptorProto_get(&m);
return EnumValueDescriptorProto(m, &m);
}
};
-class EnumValueOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class EnumValueOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- EnumValueOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ EnumValueOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_EnumValueOptions_is(m));
}
static EnumValueOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_EnumValueOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueOptions_get(&m);
return EnumValueOptions(m, &m);
}
};
-class FieldDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class FieldDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- FieldDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ FieldDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_FieldDescriptorProto_is(m));
}
static FieldDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_FieldDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldDescriptorProto_get(&m);
return FieldDescriptorProto(m, &m);
}
- class Label : public upb::reffed_ptr<const upb::EnumDef> {
+ class Label : public ::upb::reffed_ptr<const ::upb::EnumDef> {
public:
- Label(const upb::EnumDef* e, const void *ref_donor = NULL)
+ Label(const ::upb::EnumDef* e, const void *ref_donor = NULL)
: reffed_ptr(e, ref_donor) {
assert(upbdefs_google_protobuf_FieldDescriptorProto_Label_is(e));
}
static Label get() {
- const upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Label_get(&e);
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Label_get(&e);
return Label(e, &e);
}
};
- class Type : public upb::reffed_ptr<const upb::EnumDef> {
+ class Type : public ::upb::reffed_ptr<const ::upb::EnumDef> {
public:
- Type(const upb::EnumDef* e, const void *ref_donor = NULL)
+ Type(const ::upb::EnumDef* e, const void *ref_donor = NULL)
: reffed_ptr(e, ref_donor) {
assert(upbdefs_google_protobuf_FieldDescriptorProto_Type_is(e));
}
static Type get() {
- const upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Type_get(&e);
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Type_get(&e);
return Type(e, &e);
}
};
};
-class FieldOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class FieldOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- FieldOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ FieldOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_FieldOptions_is(m));
}
static FieldOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_FieldOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldOptions_get(&m);
return FieldOptions(m, &m);
}
- class CType : public upb::reffed_ptr<const upb::EnumDef> {
+ class CType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
public:
- CType(const upb::EnumDef* e, const void *ref_donor = NULL)
+ CType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
: reffed_ptr(e, ref_donor) {
assert(upbdefs_google_protobuf_FieldOptions_CType_is(e));
}
static CType get() {
- const upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_CType_get(&e);
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_CType_get(&e);
return CType(e, &e);
}
};
- class JSType : public upb::reffed_ptr<const upb::EnumDef> {
+ class JSType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
public:
- JSType(const upb::EnumDef* e, const void *ref_donor = NULL)
+ JSType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
: reffed_ptr(e, ref_donor) {
assert(upbdefs_google_protobuf_FieldOptions_JSType_is(e));
}
static JSType get() {
- const upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_JSType_get(&e);
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_JSType_get(&e);
return JSType(e, &e);
}
};
};
-class FileDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class FileDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- FileDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ FileDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_FileDescriptorProto_is(m));
}
static FileDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorProto_get(&m);
return FileDescriptorProto(m, &m);
}
};
-class FileDescriptorSet : public upb::reffed_ptr<const upb::MessageDef> {
+class FileDescriptorSet : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- FileDescriptorSet(const upb::MessageDef* m, const void *ref_donor = NULL)
+ FileDescriptorSet(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_FileDescriptorSet_is(m));
}
static FileDescriptorSet get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
return FileDescriptorSet(m, &m);
}
};
-class FileOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class FileOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- FileOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ FileOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_FileOptions_is(m));
}
static FileOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_FileOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileOptions_get(&m);
return FileOptions(m, &m);
}
- class OptimizeMode : public upb::reffed_ptr<const upb::EnumDef> {
+ class OptimizeMode : public ::upb::reffed_ptr<const ::upb::EnumDef> {
public:
- OptimizeMode(const upb::EnumDef* e, const void *ref_donor = NULL)
+ OptimizeMode(const ::upb::EnumDef* e, const void *ref_donor = NULL)
: reffed_ptr(e, ref_donor) {
assert(upbdefs_google_protobuf_FileOptions_OptimizeMode_is(e));
}
static OptimizeMode get() {
- const upb::EnumDef* e = upbdefs_google_protobuf_FileOptions_OptimizeMode_get(&e);
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FileOptions_OptimizeMode_get(&e);
return OptimizeMode(e, &e);
}
};
};
-class MessageOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class MessageOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- MessageOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ MessageOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_MessageOptions_is(m));
}
static MessageOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_MessageOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MessageOptions_get(&m);
return MessageOptions(m, &m);
}
};
-class MethodDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class MethodDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- MethodDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ MethodDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_MethodDescriptorProto_is(m));
}
static MethodDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_MethodDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodDescriptorProto_get(&m);
return MethodDescriptorProto(m, &m);
}
};
-class MethodOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class MethodOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- MethodOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ MethodOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_MethodOptions_is(m));
}
static MethodOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_MethodOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodOptions_get(&m);
return MethodOptions(m, &m);
}
};
-class OneofDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class OneofDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- OneofDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ OneofDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_OneofDescriptorProto_is(m));
}
static OneofDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_OneofDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_OneofDescriptorProto_get(&m);
return OneofDescriptorProto(m, &m);
}
};
-class ServiceDescriptorProto : public upb::reffed_ptr<const upb::MessageDef> {
+class ServiceDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- ServiceDescriptorProto(const upb::MessageDef* m, const void *ref_donor = NULL)
+ ServiceDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_ServiceDescriptorProto_is(m));
}
static ServiceDescriptorProto get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_ServiceDescriptorProto_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceDescriptorProto_get(&m);
return ServiceDescriptorProto(m, &m);
}
};
-class ServiceOptions : public upb::reffed_ptr<const upb::MessageDef> {
+class ServiceOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- ServiceOptions(const upb::MessageDef* m, const void *ref_donor = NULL)
+ ServiceOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_ServiceOptions_is(m));
}
static ServiceOptions get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_ServiceOptions_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceOptions_get(&m);
return ServiceOptions(m, &m);
}
};
-class SourceCodeInfo : public upb::reffed_ptr<const upb::MessageDef> {
+class SourceCodeInfo : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- SourceCodeInfo(const upb::MessageDef* m, const void *ref_donor = NULL)
+ SourceCodeInfo(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_SourceCodeInfo_is(m));
}
static SourceCodeInfo get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_get(&m);
return SourceCodeInfo(m, &m);
}
- class Location : public upb::reffed_ptr<const upb::MessageDef> {
+ class Location : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- Location(const upb::MessageDef* m, const void *ref_donor = NULL)
+ Location(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m));
}
static Location get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_Location_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_Location_get(&m);
return Location(m, &m);
}
};
};
-class UninterpretedOption : public upb::reffed_ptr<const upb::MessageDef> {
+class UninterpretedOption : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- UninterpretedOption(const upb::MessageDef* m, const void *ref_donor = NULL)
+ UninterpretedOption(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_UninterpretedOption_is(m));
}
static UninterpretedOption get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_get(&m);
return UninterpretedOption(m, &m);
}
- class NamePart : public upb::reffed_ptr<const upb::MessageDef> {
+ class NamePart : public ::upb::reffed_ptr<const ::upb::MessageDef> {
public:
- NamePart(const upb::MessageDef* m, const void *ref_donor = NULL)
+ NamePart(const ::upb::MessageDef* m, const void *ref_donor = NULL)
: reffed_ptr(m, ref_donor) {
assert(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m));
}
static NamePart get() {
- const upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_NamePart_get(&m);
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_NamePart_get(&m);
return NamePart(m, &m);
}
};
diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c
index fc1de78..9717f1d 100644
--- a/upb/descriptor/reader.c
+++ b/upb/descriptor/reader.c
@@ -609,6 +609,17 @@ static bool msg_endfield(void *closure, const void *hd) {
return true;
}
+static bool msg_onmapentry(void *closure, const void *hd, bool mapentry) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ UPB_UNUSED(hd);
+
+ upb_msgdef_setmapentry(m, mapentry);
+ r->f = NULL;
+ return true;
+}
+
+
/** Code to register handlers *************************************************/
@@ -679,6 +690,8 @@ static void reghandlers(const void *closure, upb_handlers *h) {
} else if (upbdefs_google_protobuf_FieldOptions_is(m)) {
upb_handlers_setbool(h, F(FieldOptions, lazy), &field_onlazy, NULL);
upb_handlers_setbool(h, F(FieldOptions, packed), &field_onpacked, NULL);
+ } else if (upbdefs_google_protobuf_MessageOptions_is(m)) {
+ upb_handlers_setbool(h, F(MessageOptions, map_entry), &msg_onmapentry, NULL);
}
assert(upb_ok(upb_handlers_status(h)));
diff --git a/upb/structdefs.int.h b/upb/structdefs.int.h
index 467374a..da9a2ec 100644
--- a/upb/structdefs.int.h
+++ b/upb/structdefs.int.h
@@ -110,14 +110,10 @@ struct upb_msgdef {
/* Tables for looking up oneofs by name. */
upb_strtable ntoo; /* name to oneof */
- /* Is this a map-entry message?
- * TODO: set this flag properly for static descriptors; regenerate
- * descriptor.upb.c. */
+ /* Is this a map-entry message? */
bool map_entry;
- /* Whether this message has proto2 or proto3 semantics.
- * TODO: set this flag properly for static descriptors; regenerate
- * descriptor.upb.c. */
+ /* Whether this message has proto2 or proto3 semantics. */
upb_syntax_t syntax;
/* TODO(haberman): proper extension ranges (there can be multiple). */
@@ -126,11 +122,11 @@ struct upb_msgdef {
/* TODO: also support static initialization of the oneofs table. This will be
* needed if we compile in descriptors that contain oneofs. */
#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
- refs, ref2s) \
+ map_entry, syntax, refs, ref2s) \
{ \
UPB_DEF_INIT(name, UPB_DEF_MSG, refs, ref2s), selector_count, \
submsg_field_count, itof, ntof, \
- UPB_EMPTY_STRTABLE_INIT(UPB_CTYPE_PTR), false, true \
+ UPB_EMPTY_STRTABLE_INIT(UPB_CTYPE_PTR), map_entry, syntax \
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback