test_json is working!

pull/13171/head
Josh Haberman 6 years ago
parent 377871f104
commit 5e958a8c05
  1. 21
      BUILD
  2. 1
      CMakeLists.txt
  3. 313
      tests/json/test.upbdefs.c
  4. 238
      tests/json/test.upbdefs.h
  5. 13
      tests/json/test_json.cc
  6. 11
      tests/test_handlers.c
  7. 2
      upb/def.c
  8. 14
      upbc/generator.cc

21
BUILD

@ -159,10 +159,17 @@ cc_test(
],
)
upb_proto_reflection_library(
name = "descriptor_upbproto",
deps = ["descriptor_proto"],
upbc = ":protoc-gen-upb",
)
cc_test(
name = "test_handlers",
srcs = ["tests/test_handlers.c"],
deps = [
":descriptor_upbproto",
":upb_pb",
":upb_test",
],
@ -221,14 +228,24 @@ cc_test(
],
)
proto_library(
name = "test_json_proto",
srcs = ["tests/json/test.proto"],
)
upb_proto_reflection_library(
name = "test_json_upbproto",
deps = ["test_json_proto"],
upbc = ":protoc-gen-upb",
)
cc_test(
name = "test_json",
srcs = [
"tests/json/test.upbdefs.c",
"tests/json/test.upbdefs.h",
"tests/json/test_json.cc",
],
deps = [
":test_json_upbproto",
":upb_json",
":upb_test",
],

@ -125,6 +125,7 @@ add_executable(test_handlers
tests/test_handlers.c)
add_test(NAME test_handlers COMMAND test_handlers)
target_link_libraries(test_handlers
descriptor_upbproto
upb_pb
upb_test)
add_executable(test_decoder

@ -1,313 +0,0 @@
/* 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 "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", 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, 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, 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, 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, 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, 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, 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, UPB_WELLKNOWN_UNSPECIFIED, &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, 3, 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, 3, 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, 3, 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, 3, 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, 3, 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, 3, 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, 5, 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]), 23, 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]), 20, 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]), 29, 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]), 26, 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]), 32, 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]), 17, 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, 43, 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, 40, 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]), 44, 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, 33, 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, 34, 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]), 11, 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, 37, 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, 35, 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, 36, 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, 69, 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, 64, 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]), 72, 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, 47, 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, 50, 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]), 14, 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, 59, 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, 53, 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, 56, 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]), 4, 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, 6, 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, 6, 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, 4, 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, 6, 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, 4, 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); }

@ -1,238 +0,0 @@
/* 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
/* 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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) { UPB_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) {
UPB_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) {
UPB_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) {
UPB_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) {
UPB_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) {
UPB_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) {
UPB_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) {
UPB_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) {
UPB_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) {
UPB_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_ */

@ -203,12 +203,13 @@ 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<const upb::MessageDef> md(
upbdefs::upb::test::json::TestMessage::get());
upb::SymbolTable* symtab = upb::SymbolTable::New();
const upb::MessageDef* md = upb_test_json_TestMessage_getmsgdef(symtab);
ASSERT(md);
upb::reffed_ptr<const upb::Handlers> serialize_handlers(
upb::json::Printer::NewHandlers(md.get(), false));
upb::json::Printer::NewHandlers(md, false));
upb::reffed_ptr<const upb::json::ParserMethod> parser_method(
upb::json::ParserMethod::New(md.get()));
upb::json::ParserMethod::New(md));
for (const TestCase* test_case = kTestRoundtripMessages;
test_case->input != NULL; test_case++) {
@ -224,7 +225,7 @@ void test_json_roundtrip() {
}
}
serialize_handlers = upb::json::Printer::NewHandlers(md.get(), true);
serialize_handlers = upb::json::Printer::NewHandlers(md, true);
for (const TestCase* test_case = kTestRoundtripMessagesPreserve;
test_case->input != NULL; test_case++) {
@ -239,6 +240,8 @@ void test_json_roundtrip() {
i);
}
}
upb::SymbolTable::Free(symtab);
}
extern "C" {

@ -1,9 +1,9 @@
#include "upb/handlers.h"
#include "upb/descriptor/descriptor.upbdefs.h"
#include "upb_test.h"
#include <stdlib.h>
#include <string.h>
#include "google/protobuf/descriptor.upbdefs.h"
#include "upb/handlers.h"
#include "upb_test.h"
static bool startmsg(void *c, const void *hd) {
UPB_UNUSED(c);
@ -13,9 +13,9 @@ static bool startmsg(void *c, const void *hd) {
static void test_error() {
/* Test creating handlers of a static msgdef. */
const upb_msgdef *m = upbdefs_google_protobuf_DescriptorProto_get(&m);
upb_symtab *s = upb_symtab_new();
const upb_msgdef *m = google_protobuf_DescriptorProto_getmsgdef(s);
upb_handlers *h = upb_handlers_new(m, &h);
upb_msgdef_unref(m, &m);
/* Attempt to set the same handler twice causes error. */
ASSERT(upb_ok(upb_handlers_status(h)));
@ -31,6 +31,7 @@ static void test_error() {
ASSERT(upb_handlers_isfrozen(h));
upb_handlers_unref(h, &h);
upb_symtab_free(s);
}
int run_tests(int argc, char *argv[]) {

@ -467,7 +467,7 @@ bool upb_fielddef_packed(const upb_fielddef *f) {
}
const char *upb_fielddef_name(const upb_fielddef *f) {
return f->full_name;
return shortdefname(f->full_name);
}
uint32_t upb_fielddef_selectorbase(const upb_fielddef *f) {

@ -587,7 +587,11 @@ void GenerateMessageDefAccessor(const protobuf::Descriptor* d, Output& output) {
void WriteDefHeader(const protobuf::FileDescriptor* file, Output& output) {
EmitFileWarning(file, output);
output("#include \"upb/def.h\"\n");
output("\n");
output("extern upb_def_init $0;\n", DefInitSymbol(file));
output("\n");
for (int i = 0; i < file->message_type_count(); i++) {
GenerateMessageDefAccessor(file->message_type(i), output);
@ -621,10 +625,10 @@ void WriteDefSource(const protobuf::FileDescriptor* file, Output& output) {
// Workaround for MSVC: "Error C1091: compiler limit: string exceeds
// 65535 bytes in length". Declare a static array of chars rather than
// use a string literal. Only write 25 bytes per line.
static const int kBytesPerLine = 25;
static const size_t kBytesPerLine = 25;
output("{ ");
for (int i = 0; i < file_data.size();) {
for (int j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) {
for (size_t i = 0; i < file_data.size();) {
for (size_t j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) {
output("'$0', ", absl::CEscape(file_data.substr(i, 1)));
}
output("\n");
@ -632,8 +636,8 @@ void WriteDefSource(const protobuf::FileDescriptor* file, Output& output) {
output("'\\0' }"); // null-terminate
} else {
// Only write 40 bytes per line.
static const int kBytesPerLine = 40;
for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
static const size_t kBytesPerLine = 40;
for (size_t i = 0; i < file_data.size(); i += kBytesPerLine) {
output(
"\"$0\"\n",
EscapeTrigraphs(absl::CEscape(file_data.substr(i, kBytesPerLine))));

Loading…
Cancel
Save