diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2016-04-19 15:41:33 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2016-04-19 15:41:33 -0700 |
commit | e6fa3f9d869765544b8e424e8573fe8d9af35534 (patch) | |
tree | 3e56beb3bd80470ddad130b2c7f703fb5bb6b5fd /tests/json/test.upbdefs.h | |
parent | 68bc62a7fa5febbf5c8ab2fe8f6171121d18690f (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.
Diffstat (limited to 'tests/json/test.upbdefs.h')
-rw-r--r-- | tests/json/test.upbdefs.h | 246 |
1 files changed, 246 insertions, 0 deletions
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_ */ |