diff options
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | DESIGN.md | 83 | ||||
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | tests/conformance_upb.c | 165 | ||||
m--------- | third_party/protobuf | 0 | ||||
-rw-r--r-- | tools/make_c_api.lua | 515 | ||||
-rw-r--r-- | tools/upbc.lua | 60 | ||||
-rw-r--r-- | upb/bindings/lua/def.c | 78 | ||||
-rw-r--r-- | upb/decode.c | 385 | ||||
-rw-r--r-- | upb/decode.h | 17 | ||||
-rw-r--r-- | upb/descriptor/descriptor.upb.c | 1611 | ||||
-rw-r--r-- | upb/descriptor/descriptor.upb.h | 527 | ||||
-rw-r--r-- | upb/descriptor/reader.c | 18 | ||||
-rw-r--r-- | upb/encode.c | 381 | ||||
-rw-r--r-- | upb/encode.h | 17 | ||||
-rw-r--r-- | upb/msg.c | 16 | ||||
-rw-r--r-- | upb/msg.h | 17 | ||||
-rw-r--r-- | upb/structs.int.h | 18 | ||||
-rw-r--r-- | upb/upb.h | 3 |
19 files changed, 3902 insertions, 35 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8b52c1d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/protobuf"] + path = third_party/protobuf + url = https://github.com/google/protobuf.git diff --git a/DESIGN.md b/DESIGN.md new file mode 100644 index 0000000..4e6dc04 --- /dev/null +++ b/DESIGN.md @@ -0,0 +1,83 @@ + +μpb Design +---------- + +**NOTE:** the design described here is being implemented currently, but is not +yet complete. The repo is in heavy transition right now. + +μpb has the following design goals: + +- C89 compatible. +- small code size (both for the core library and generated messages). +- fast performance (hundreds of MB/s). +- idiomatic for C programs. +- easy to wrap in high-level languages (Python, Ruby, Lua, etc) with + good performance and all standard protobuf features. +- hands-off about memory management, allowing for easy integration + with existing VMs and/or garbage collectors. +- offers binary ABI compatibility between apps, generated messages, and + the core library (doesn't require re-generating messages or recompiling + your application when the core library changes). +- provides all features that users expect from a protobuf library + (generated messages in C, reflection, text format, etc.). +- layered, so the core is small and doesn't require descriptors. +- tidy about symbol references, so that any messages or features that + aren't used by a C program can have their code GC'd by the linker. +- possible to use protobuf binary format without leaking message/field + names into the binary. + +μpb accomplishes these goals by keeping a very small core that does not contain +descriptors. We need some way of knowing what fields are in each message and +where they live, but instead of descriptors, we keep a small/lightweight summary +of the .proto file. We call this a `upb_msglayout`. It contains the bare +minimum of what we need to know to parse and serialize protobuf binary format +into our internal representation for messages, `upb_msg`. + +The core then contains functions to parse/serialize a message, given a `upb_msg*` +and a `const upb_msglayout*`. + +This approach is similar to [nanopb](https://github.com/nanopb/nanopb) which +also compiles message definitions to a compact, internal representation without +names. However nanopb does not aim to be a fully-featured library, and has no +support for text format, JSON, or descriptors. μpb is unique in that it has a +small core similar to nanopb (though not quite as small), but also offers a +full-featured protobuf library for applications that want reflection, text +format, JSON format, etc. + +Without descriptors, the core doesn't have access to field names, so it cannot +parse/serialize to protobuf text format or JSON. Instead this functionality +lives in separate modules that depend on the module implementing descriptors. +With the descriptor module we can parse/serialize binary descriptors and +validate that they follow all the rules of protobuf schemas. + +To provide binary compatibility, we version the structs that generated messages +use to create a `upb_msglayout*`. The current initializers are +`upb_msglayout_msginit_v1`, `upb_msglayout_fieldinit_v1`, etc. Then +`upb_msglayout*` uses these as its internal representation. If upb changes its +internal representation for a `upb_msglayout*`, it will also include code to +convert the old representation to the new representation. This will use some +more memory/CPU at runtime to convert between the two, but apps that statically +link μpb will never need to worry about this. + +TODO +---- + +The current state of the repo is quite different than what is described above. +Here are the major items that need to be implemented. + +1. implement the core generic protobuf binary encoder/decoder that uses a + `upb_msglayout*`. +2. remove all mention of handlers, sink, etc. from core into their own module. + All of the handlers stuff needs substantial revision, but moving it out of + core is the first priority. +3. move all of the def/refcounted stuff out of core. The defs also need + substantial revision, but moving them out of core is the first priority. +4. revise our generated code until it is in a state where we feel comfortable + committing to API/ABI stability for it. This may involve moving different + parts of the generated code into separate files, like keeping the serialized + descriptor in a separate file from the compact msglayout. +5. revise all of the existing encoders/decoders and handlers. We probably + will want to keep handlers, since they let us decouple encoders/decoders + from `upb_msg`, but we need to simplify all of that a LOT. Likely we will + want to make handlers only per-message instead of per-field, except for + variable-length fields. @@ -110,7 +110,7 @@ clean_leave_profile: @rm -rf obj lib @rm -f tests/google_message?.h @rm -f tests/json/test.upbdefs.o - @rm -f $(TESTS) tests/testmain.o tests/t.* + @rm -f $(TESTS) tests/testmain.o tests/t.* tests/conformance_upb @rm -rf tools/upbc deps @rm -rf upb/bindings/python/build @rm -f upb/bindings/ruby/Makefile @@ -148,7 +148,9 @@ make_objs_cc = $$(patsubst upb/$$(pc).cc,obj/upb/$$(pc).$(1),$$($$(call to_srcs, # Core libraries (ie. not bindings). ############################################################### upb_SRCS = \ + upb/decode.c \ upb/def.c \ + upb/encode.c \ upb/handlers.c \ upb/msg.c \ upb/refcounted.c \ @@ -262,11 +264,11 @@ genfiles: tools/upbc $(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 + $(Q) ./tools/upbc --generate-upbdefs 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 + $(Q) ./tools/upbc --generate-upbdefs 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) @@ -361,6 +363,21 @@ test: done; @echo "All tests passed!" +obj/conformance_protos: obj/conformance_protos.pb tools/upbc + cd obj && ../tools/upbc conformance_protos.pb && touch conformance_protos + +obj/conformance_protos.pb: third_party/protobuf/autogen.sh + protoc -Ithird_party/protobuf/conformance -Ithird_party/protobuf/src --include_imports \ + third_party/protobuf/conformance/conformance.proto \ + third_party/protobuf/src/google/protobuf/test_messages_proto3.proto \ + -o obj/conformance_protos.pb + +third_party/protouf/autogen.sh: .gitmodules + git submodule init && git submodule update + +tests/conformance_upb: tests/conformance_upb.c lib/libupb.a obj/conformance_protos + $(CC) -o tests/conformance_upb tests/conformance_upb.c -Iobj -I. $(CPPFLAGS) $(CFLAGS) obj/conformance.upb.c obj/google/protobuf/*.upb.c lib/libupb.a + # Google protobuf binding ###################################################### diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c new file mode 100644 index 0000000..e1221b2 --- /dev/null +++ b/tests/conformance_upb.c @@ -0,0 +1,165 @@ +/* This is a upb implementation of the upb conformance tests, see: + * https://github.com/google/protobuf/tree/master/conformance + */ + +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "conformance.upb.h" +#include "google/protobuf/test_messages_proto3.upb.h" + +int test_count = 0; + +bool CheckedRead(int fd, void *buf, size_t len) { + size_t ofs = 0; + while (len > 0) { + ssize_t bytes_read = read(fd, (char*)buf + ofs, len); + + if (bytes_read == 0) return false; + + if (bytes_read < 0) { + perror("reading from test runner"); + exit(1); + } + + len -= bytes_read; + ofs += bytes_read; + } + + return true; +} + +void CheckedWrite(int fd, const void *buf, size_t len) { + if (write(fd, buf, len) != len) { + perror("writing to test runner"); + exit(1); + } +} + +void DoTest( + const conformance_ConformanceRequest* request, + conformance_ConformanceResponse *response, + upb_env *env) { + conformance_ConformanceResponse_new(env); + protobuf_test_messages_proto3_TestAllTypes *test_message; + + switch (conformance_ConformanceRequest_payload_case(request)) { + case conformance_ConformanceRequest_payload_protobuf_payload: + test_message = protobuf_test_messages_proto3_TestAllTypes_parsenew( + conformance_ConformanceRequest_protobuf_payload(request), env); + + if (!test_message) { + /* TODO(haberman): return details. */ + static const char msg[] = "Parse error (no more details available)."; + conformance_ConformanceResponse_set_parse_error( + response, upb_stringview_make(msg, sizeof(msg))); + return; + } + break; + + case conformance_ConformanceRequest_payload_json_payload: { + static const char msg[] = "JSON support not yet implemented."; + conformance_ConformanceResponse_set_skipped( + response, upb_stringview_make(msg, sizeof(msg))); + return; + } + + case conformance_ConformanceRequest_payload_NOT_SET: + fprintf(stderr, "conformance_upb: Request didn't have payload.\n"); + return; + } + + switch (conformance_ConformanceRequest_requested_output_format(request)) { + case conformance_UNSPECIFIED: + fprintf(stderr, "conformance_upb: Unspecified output format.\n"); + exit(1); + + case conformance_PROTOBUF: { + size_t serialized_len; + char *serialized = protobuf_test_messages_proto3_TestAllTypes_serialize( + test_message, env, &serialized_len); + if (!serialized) { + static const char msg[] = "Error serializing."; + conformance_ConformanceResponse_set_serialize_error( + response, upb_stringview_make(msg, sizeof(msg))); + return; + } + conformance_ConformanceResponse_set_protobuf_payload( + response, upb_stringview_make(serialized, serialized_len)); + break; + } + + case conformance_JSON: { + static const char msg[] = "JSON support not yet implemented."; + conformance_ConformanceResponse_set_skipped( + response, upb_stringview_make(msg, sizeof(msg))); + break; + } + + default: + fprintf(stderr, "conformance_upb: Unknown output format: %d\n", + conformance_ConformanceRequest_requested_output_format(request)); + exit(1); + } + + return; +} + +bool DoTestIo() { + upb_env env; + upb_status status; + char *serialized_input; + char *serialized_output; + uint32_t input_size; + size_t output_size = 0; + conformance_ConformanceRequest *request; + conformance_ConformanceResponse *response; + + if (!CheckedRead(STDIN_FILENO, &input_size, sizeof(uint32_t))) { + // EOF. + return false; + } + + upb_env_init(&env); + upb_env_reporterrorsto(&env, &status); + serialized_input = upb_env_malloc(&env, input_size); + + if (!CheckedRead(STDIN_FILENO, serialized_input, input_size)) { + fprintf(stderr, "conformance_upb: unexpected EOF on stdin.\n"); + exit(1); + } + + request = conformance_ConformanceRequest_parsenew( + upb_stringview_make(serialized_input, input_size), &env); + response = conformance_ConformanceResponse_new(&env); + + if (request) { + DoTest(request, response, &env); + } else { + fprintf(stderr, "conformance_upb: parse of ConformanceRequest failed: %s\n", + upb_status_errmsg(&status)); + } + + serialized_output = conformance_ConformanceResponse_serialize( + response, &env, &output_size); + + CheckedWrite(STDOUT_FILENO, &output_size, sizeof(uint32_t)); + CheckedWrite(STDOUT_FILENO, serialized_output, output_size); + + test_count++; + + return true; +} + +int main() { + while (1) { + if (!DoTestIo()) { + fprintf(stderr, "conformance_upb: received EOF from test runner " + "after %d tests, exiting\n", test_count); + return 0; + } + } +} diff --git a/third_party/protobuf b/third_party/protobuf new file mode 160000 +Subproject 6bd51a59df41b99058ec8c2b03a177a218267ce diff --git a/tools/make_c_api.lua b/tools/make_c_api.lua new file mode 100644 index 0000000..62fd370 --- /dev/null +++ b/tools/make_c_api.lua @@ -0,0 +1,515 @@ +--[[ + + Code to generate a C API in: + foo.proto -> foo.upb.h + foo.upb.c + + This code is evolving very quickly and so there are lots of little things + that aren't perfect right now. As it settles a little more, the code + quality should improve. + +--]] + +local upb = require "upb" +local dump_cinit = require "dump_cinit" +local export = {} + +local typemap = { + [upb.TYPE_BOOL] = "bool", + [upb.TYPE_FLOAT] = "float", + [upb.TYPE_INT32] = "int32_t", + [upb.TYPE_UINT32] = "uint32_t", + [upb.TYPE_DOUBLE] = "double", + [upb.TYPE_INT64] = "int64_t", + [upb.TYPE_UINT64] = "uint64_t", + [upb.TYPE_STRING] = "upb_stringview", + [upb.TYPE_BYTES] = "upb_stringview", +} + +function strip_proto(filename) + return string.gsub(filename, '%.proto$','') +end + +--[[ + [upb.TYPE_ENUM] = 5, + [upb.TYPE_MESSAGE] = 8, +--]] + +local function join(...) + return table.concat({...}, ".") +end + +local function to_cident(...) + return string.gsub(join(...), "[%./]", "_") +end + +local function to_preproc(...) + return string.upper(to_cident(...)) +end + +-- Strips away last path element, ie: +-- foo.Bar.Baz -> foo.Bar +local function remove_name(name) + local package_end = 0 + for i=1,string.len(name) do + if string.byte(name, i) == string.byte(".", 1) then + package_end = i - 1 + end + end + return string.sub(name, 1, package_end) +end + +local function enum_value_symbol(enumdef, name) + return to_cident(remove_name(enumdef:full_name())) .. "_" .. name +end + +local function dump_enum_vals(enumdef, append) + local enum_vals = {} + + for k, v in enumdef:values() do + enum_vals[#enum_vals + 1] = {k, v} + end + + table.sort(enum_vals, function(a, b) return a[2] < b[2] end) + + -- protobuf convention is that enum values are scoped at the level of the + -- enum itself, to follow C++. Ie, if you have the enum: + -- message Foo { + -- enum E { + -- VAL1 = 1; + -- VAL2 = 2; + -- } + -- } + -- + -- The name of VAL1 is Foo.VAL1, not Foo.E.VAL1. + -- + -- This seems a bit sketchy, but people often name their enum values + -- accordingly, ie: + -- + -- enum Foo { + -- FOO_VAL1 = 1; + -- FOO_VAL2 = 2; + -- } + -- + -- So if we don't respect this also, we end up with constants that look like: + -- + -- GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_TYPE_DOUBLE = 1 + -- + -- (notice the duplicated "TYPE"). + local cident = to_cident(remove_name(enumdef:full_name())) + for i, pair in ipairs(enum_vals) do + k, v = pair[1], pair[2] + append(' %s = %d', enum_value_symbol(enumdef, k), v) + if i == #enum_vals then + append('\n') + else + append(',\n') + end + end +end + +local function field_default(field) + if field:type() == upb.TYPE_MESSAGE then + return "NULL" + elseif field:type() == upb.TYPE_STRING or + field:type() == upb.TYPE_BYTES then + local default = field:default() or "" + return string.format('upb_stringview_make("%s", strlen("%s"))', field:default(), field:default()) + elseif field:type() == upb.TYPE_ENUM then + return enum_value_symbol(field:subdef(), field:default()) + else + return field:default(); + end +end + +local function ctype(field) + if field:label() == upb.LABEL_REPEATED then + return "upb_array*" + elseif field:type() == upb.TYPE_MESSAGE then + if field:containing_type():file() == field:subdef():file() then + return to_cident(field:subdef():full_name()) .. "*" + else + return "struct " .. to_cident(field:subdef():full_name()) .. "*" + end + elseif field:type() == upb.TYPE_ENUM then + return to_cident(field:subdef():full_name()) + else + return typemap[field:type()] or "void*" + end +end + +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 + +local function field_layout_rank(field) + -- Order: + -- 1, 2, 3. primitive fields (8, 4, 1 byte) + -- 4. string fields + -- 5. submessage fields + -- 6. repeated fields + local rank + if field:containing_oneof() then + rank = 100 -- These go last (actually we skip them). + elseif field:label() == upb.LABEL_REPEATED then + rank = 6 + elseif field:type() == upb.TYPE_MESSAGE then + rank = 5 + elseif field:type() == upb.TYPE_STRING or field:type() == upb.TYPE_BYTES then + rank = 4 + elseif field:type() == upb.TYPE_BOOL then + rank = 3 + elseif field:type() == upb.TYPE_FLOAT or + field:type() == upb.TYPE_INT32 or + field:type() == upb.TYPE_UINT32 then + rank = 2 + else + rank = 1 + end + + -- Break ties with field number. + return (rank * 2^29) + field:number() +end + +local function has_hasbit(field) + if field:containing_type():file():syntax() == upb.SYNTAX_PROTO2 then + return field:label() ~= upb.LABEL_REPEATED and not field:containing_oneof() + else + return false + end +end + +local function write_h_file(filedef, append) + emit_file_warning(filedef, append) + local basename_preproc = to_preproc(filedef:name()) + append('#ifndef %s_UPB_H_\n', basename_preproc) + append('#define %s_UPB_H_\n\n', basename_preproc) + + append('#include "upb/msg.h"\n\n') + + append('UPB_BEGIN_EXTERN_C\n\n') + + for msg in filedef:defs(upb.DEF_MSG) do + -- TODO(haberman): forward declare C++ type names so we can use + -- UPB_DECLARE_TYPE(). + local msgname = to_cident(msg:full_name()) + append('struct %s;\n', msgname) + append('typedef struct %s %s;\n', msgname, msgname) + end + + append("/* Enums */\n\n") + for _, def in ipairs(sorted_defs(filedef:defs(upb.DEF_ENUM))) do + local cident = to_cident(def:full_name()) + append('typedef enum {\n') + dump_enum_vals(def, append) + append('} %s;\n\n', cident) + end + + for msg in filedef:defs(upb.DEF_MSG) do + local msgname = to_cident(msg:full_name()) + append('/* %s message definition. */\n', msgname) + append('extern const upb_msglayout_msginit_v1 %s_msginit;\n', msgname) + append('%s *%s_new(upb_env *env);\n', msgname, msgname) + append('%s *%s_parsenew(upb_stringview buf, upb_env *env);\n', + msgname, msgname) + append('char *%s_serialize(%s *msg, upb_env *env, size_t *len);\n', + msgname, msgname) + append('void %s_free(%s *msg, upb_env *env);\n', msgname, msgname) + append('\n') + + append('/* %s getters. */\n', msgname) + local setters, get_setters = dump_cinit.str_appender() + for field in msg:fields() do + local fieldname = to_cident(field:name()) + if field:type() == upb.TYPE_MESSAGE and + field:subdef():file() ~= filedef then + -- Forward declaration for message type declared in another file. + append('struct %s;\n', to_cident(field:subdef():full_name())) + end + if field:label() == upb.LABEL_REPEATED then + else + local typename = ctype(field) + append('%s %s_%s(const %s *msg);\n', + typename, msgname, fieldname, msgname) + setters('void %s_set_%s(%s *msg, %s value);\n', + msgname, fieldname, msgname, typename) + end + end + + for oneof in msg:oneofs() do + local fullname = to_cident(oneof:containing_type():full_name() .. "." .. oneof:name()) + append('typedef enum {\n') + for field in oneof:fields() do + append(' %s = %d,\n', fullname .. "_" .. field:name(), field:number()) + end + append(' %s_NOT_SET = 0,\n', fullname) + append('} %s_oneofcases;\n', fullname) + append('%s_oneofcases %s_case(const %s *msg);\n', fullname, fullname, msgname) + end + + append('\n') + append('/* %s setters. */\n', msgname) + append(get_setters()) + + append('\n') + append('\n') + end + + append('UPB_END_EXTERN_C') + + append('\n') + append('\n') + + append('#endif /* %s_UPB_H_ */\n', basename_preproc) +end + +local function write_c_file(filedef, hfilename, append) + emit_file_warning(filedef, append) + + append('#include <stddef.h>\n') + append('#include "upb/decode.h"\n\n') + append('#include "upb/encode.h"\n\n') + append('#include "upb/msg.h"\n') + append('#include "upb/upb.h"\n') + append('#include "%s"\n\n', hfilename) + + for dep in filedef:dependencies() do + local outbase = strip_proto(dep:name()) + append('#include "%s.upb.h"\n', outbase) + end + + append('\n') + + for msg in filedef:defs(upb.DEF_MSG) do + local msgname = to_cident(msg:full_name()) + + local fields_array_ref = "NULL" + local submsgs_array_ref = "NULL" + local oneofs_array_ref = "NULL" + local field_count = 0 + local submsg_count = 0 + local submsg_set = {} + local submsg_indexes = {} + local hasbit_count = 0 + local hasbit_indexes = {} + local oneof_count = 0 + local oneof_indexes = {} + + -- Create a layout order for oneofs. + local oneofs_layout_order = {} + for oneof in msg:oneofs() do + table.insert(oneofs_layout_order, oneof) + end + table.sort(oneofs_layout_order, function(a, b) + return a:name() < b:name() + end) + + for _, oneof in ipairs(oneofs_layout_order) do + oneof_indexes[oneof] = oneof_count + oneof_count = oneof_count + 1 + end + + -- Create a layout order for fields. We use this order for the struct and + -- for offsets, but our list of fields we keep in field number order. + local fields_layout_order = {} + for field in msg:fields() do + table.insert(fields_layout_order, field) + end + table.sort(fields_layout_order, function(a, b) + return field_layout_rank(a) < field_layout_rank(b) + end) + + -- Another sorted array in field number order. + local fields_number_order = {} + for field in msg:fields() do + table.insert(fields_number_order, field) + end + table.sort(fields_number_order, function(a, b) + return a:number() < b:number() + end) + + append('struct %s {\n', msgname) + + -- Non-oneof fields. + for _, field in ipairs(fields_layout_order) do + field_count = field_count + 1 + + if field:type() == upb.TYPE_MESSAGE then + submsg_count = submsg_count + 1 + submsg_set[field:subdef()] = true + end + + if field:containing_oneof() then + -- Do nothing now + else + if has_hasbit(field) then + hasbit_indexes[field] = hasbit_count + hasbit_count = hasbit_count + 1 + end + + append(' %s %s;\n', ctype(field), field:name()) + end + end + + local oneof_last_fields = {} + -- Oneof fields. + for oneof in msg:oneofs() do + local fullname = to_cident(oneof:containing_type():full_name() .. "." .. oneof:name()) + append(' union {\n') + oneof_last_fields[oneof] = "" + for field in oneof:fields() do + oneof_last_fields[oneof] = field:name() + append(' %s %s;\n', ctype(field), field:name()) + end + append(' } %s;\n', oneof:name()) + append(' %s_oneofcases %s_case;\n', fullname, oneof:name()) + end + + append('};\n\n') + + if oneof_count > 0 then + local oneofs_array_name = msgname .. "_oneofs" + oneofs_array_ref = "&" .. oneofs_array_name .. "[0]" + append('static const upb_msglayout_oneofinit_v1 %s[%s] = {\n', + oneofs_array_name, oneof_count) + for _, oneof in ipairs(oneofs_layout_order) do + append(' {offsetof(%s, %s), offsetof(%s, %s_case)},\n', + msgname, oneof:name(), msgname, oneof:name()) + end + append('};\n\n') + end + + if submsg_count > 0 then + -- TODO(haberman): could save a little bit of space by only generating a + -- "submsgs" array for every strongly-connected component. + local submsgs_array_name = msgname .. "_submsgs" + submsgs_array_ref = "&" .. submsgs_array_name .. "[0]" + append('static const upb_msglayout_msginit_v1 *const %s[%s] = {\n', + submsgs_array_name, submsg_count) + + -- Create a deterministically-sorted array of submessage entries. + local submsg_array = {} + for k, v in pairs(submsg_set) do + table.insert(submsg_array, k) + end + table.sort(submsg_array, function(a, b) + return a:full_name() < b:full_name() + end) + + for i, submsg in ipairs(submsg_array) do + append(' &%s_msginit,\n', to_cident(submsg:full_name())) + submsg_indexes[submsg] = i - 1 + end + + append('};\n\n') + end + + if field_count > 0 then + local fields_array_name = msgname .. "__fields" + fields_array_ref = "&" .. fields_array_name .. "[0]" + append('static const upb_msglayout_fieldinit_v1 %s[%s] = {\n', + fields_array_name, field_count) + for _, field in ipairs(fields_number_order) do + local submsg_index = "-1" + local oneof_index = "UPB_NOT_IN_ONEOF" + if field:type() == upb.TYPE_MESSAGE then + submsg_index = submsg_indexes[field:subdef()] + end + if field:containing_oneof() then + oneof_index = oneof_indexes[field:containing_oneof()] + end + -- TODO(haberman): oneofs. + append(' {%s, offsetof(%s, %s), %s, %s, %s, %s, %s},\n', + field:number(), + msgname, + (field:containing_oneof() and field:containing_oneof():name()) or field:name(), + hasbit_indexes[field] or "-1", + oneof_index, + submsg_index, + field:descriptor_type(), + field:label()) + end + append('};\n\n') + end + + append('const upb_msglayout_msginit_v1 %s_msginit = {\n', msgname) + append(' %s,\n', submsgs_array_ref) + append(' %s,\n', fields_array_ref) + append(' %s,\n', oneofs_array_ref) + append(' NULL, /* TODO. default_msg */\n') + append(' UPB_ALIGNED_SIZEOF(%s), %s, %s, %s, %s\n', + msgname, field_count, + 0, -- TODO: oneof_count + 'false', -- TODO: extendable + 'true' -- TODO: is_proto2 + ) + append('};\n\n') + + append('%s *%s_new(upb_env *env) {\n', msgname, msgname) + append(' %s *msg = upb_env_malloc(env, sizeof(*msg));\n', + msgname) + append(' memset(msg, 0, sizeof(*msg)); /* TODO: defaults */\n') + append(' return msg;\n') + append('}\n') + + append('%s *%s_parsenew(upb_stringview buf, upb_env *env) {\n', + msgname, msgname) + append(' %s *msg = %s_new(env);\n', msgname, msgname) + append(' if (upb_decode(buf, msg, &%s_msginit, env)) {\n', msgname) + append(' return msg;\n') + append(' } else {\n') + append(' return NULL;\n') + append(' }\n') + append('}\n') + + append('char *%s_serialize(%s *msg, upb_env *env, size_t *size) {\n', + msgname, msgname) + append(' return upb_encode(msg, &%s_msginit, env, size);\n', msgname) + append('}\n') + + for field in msg:fields() do + local typename = ctype(field) + append('%s %s_%s(const %s *msg) {\n', + typename, msgname, field:name(), msgname); + if field:containing_oneof() then + local oneof = field:containing_oneof() + append(' return msg->%s_case == %s ? msg->%s.%s : %s;\n', + oneof:name(), field:number(), oneof:name(), field:name(), + field_default(field)) + else + append(' return msg->%s;\n', field:name()) + end + append('}\n') + append('void %s_set_%s(%s *msg, %s value) {\n', + msgname, field:name(), msgname, typename); + if field:containing_oneof() then + local oneof = field:containing_oneof() + append(' msg->%s.%s = value;\n', oneof:name(), field:name()) + append(' msg->%s_case = %s;\n', oneof:name(), field:number()) + else + append(' msg->%s = value;\n', field:name()) + end + append('}\n') + end + + for oneof in msg:oneofs() do + local fullname = to_cident(oneof:containing_type():full_name() .. "." .. oneof:name()) + append('%s_oneofcases %s_case(const %s *msg) {\n', fullname, fullname, msgname) + append(' return msg->%s_case;\n', oneof:name()) + append('}\n') + end + end +end + +function export.write_gencode(filedef, hfilename, append_h, append_c) + write_h_file(filedef, append_h) + write_c_file(filedef, hfilename, append_c) +end + +return export diff --git a/tools/upbc.lua b/tools/upbc.lua index 5db5fba..9d9531c 100644 --- a/tools/upbc.lua +++ b/tools/upbc.lua @@ -1,20 +1,34 @@ --[[ - The upb compiler. Unlike the proto2 compiler, this does - not output any parsing code or generated classes or anything - specific to the protobuf binary format at all. At the moment - it only dumps C initializers for upb_defs, so that a .proto - file can be represented in a .o file. + The upb compiler. It can write two different kinds of output + files: + + - generated code for a C API (foo.upb.h, foo.upb.c) + - (obsolete): definitions of upb defs. (foo.upbdefs.h, foo.upbdefs.c) --]] local dump_cinit = require "dump_cinit" +local make_c_api = require "make_c_api" local upb = require "upb" -local src = arg[1] +local generate_upbdefs = false + +for _, argument in ipairs(arg) do + if argument.sub(argument, 1, 2) == "--" then + if argument == "--generate-upbdefs" then + generate_upbdefs = true + else + print("Unknown flag: " .. argument) + return 1 + end + else + src = argument + end +end if not src then - print("Usage: upbc <binary descriptor>") + print("Usage: upbc [--generate-upbdefs] <binary descriptor>") return 1 end @@ -32,6 +46,8 @@ for _, file in ipairs(files) do symtab:add_file(file) local outbase = strip_proto(file:name()) + -- Write upbdefs. + local hfilename = outbase .. ".upbdefs.h" local cfilename = outbase .. ".upbdefs.c" @@ -44,14 +60,40 @@ for _, file in ipairs(files) do end os.execute(string.format("mkdir -p `dirname %s`", outbase)) + + if generate_upbdefs then + -- Legacy generated defs. + local hfile = assert(io.open(hfilename, "w"), "couldn't open " .. hfilename) + local cfile = assert(io.open(cfilename, "w"), "couldn't open " .. cfilename) + + local happend = dump_cinit.file_appender(hfile) + local cappend = dump_cinit.file_appender(cfile) + + dump_cinit.dump_defs(file, happend, cappend) + + hfile:close() + cfile:close() + end + + -- Write C API. + hfilename = outbase .. ".upb.h" + cfilename = outbase .. ".upb.c" + + if os.getenv("UPBC_VERBOSE") then + print("upbc:") + print(string.format(" source file=%s", src)) + print(string.format(" output file base=%s", outbase)) + print(string.format(" hfilename=%s", hfilename)) + print(string.format(" cfilename=%s", cfilename)) + end + local hfile = assert(io.open(hfilename, "w"), "couldn't open " .. hfilename) local cfile = assert(io.open(cfilename, "w"), "couldn't open " .. cfilename) local happend = dump_cinit.file_appender(hfile) local cappend = dump_cinit.file_appender(cfile) - -- Dump defs - dump_cinit.dump_defs(file, happend, cappend) + make_c_api.write_gencode(file, hfilename, happend, cappend) hfile:close() cfile:close() diff --git a/upb/bindings/lua/def.c b/upb/bindings/lua/def.c index 5133831..194acc3 100644 --- a/upb/bindings/lua/def.c +++ b/upb/bindings/lua/def.c @@ -211,6 +211,7 @@ bool lupb_def_pushwrapper(lua_State *L, const upb_def *def, type = LUPB_ENUMDEF; break; default: + printf("Def type: %d\n", (int)upb_def_type(def)); UPB_UNREACHABLE(); } @@ -231,6 +232,15 @@ static int lupb_def_type(lua_State *L) { return 1; } +void lupb_filedef_pushwrapper(lua_State *L, const upb_filedef *f, + const void *ref_donor); + +static int lupb_def_file(lua_State *L) { + const upb_def *def = lupb_def_check(L, 1); + lupb_filedef_pushwrapper(L, upb_def_file(def), NULL); + return 1; +} + static int lupb_def_freeze(lua_State *L) { upb_def *def = lupb_def_checkmutable(L, 1); CHK(upb_def_freeze(&def, 1, &status)); @@ -263,6 +273,7 @@ static int lupb_def_setfullname(lua_State *L) { #define LUPB_COMMON_DEF_METHODS \ {"def_type", lupb_def_type}, \ + {"file", lupb_def_file}, \ {"full_name", lupb_def_fullname}, \ {"freeze", lupb_def_freeze}, \ {"is_frozen", lupb_def_isfrozen}, \ @@ -296,6 +307,15 @@ static int lupb_fielddef_new(lua_State *L) { /* Getters */ +void lupb_oneofdef_pushwrapper(lua_State *L, const upb_oneofdef *o, + const void *ref_donor); + +static int lupb_fielddef_containingoneof(lua_State *L) { + const upb_fielddef *f = lupb_fielddef_check(L, 1); + lupb_oneofdef_pushwrapper(L, upb_fielddef_containingoneof(f), NULL); + return 1; +} + static int lupb_fielddef_containingtype(lua_State *L) { const upb_fielddef *f = lupb_fielddef_check(L, 1); lupb_msgdef_pushwrapper(L, upb_fielddef_containingtype(f), NULL); @@ -349,6 +369,12 @@ static int lupb_fielddef_default(lua_State *L) { return 1; } +static int lupb_fielddef_descriptortype(lua_State *L) { + const upb_fielddef *f = lupb_fielddef_check(L, 1); + lua_pushnumber(L, upb_fielddef_descriptortype(f)); + return 1; +} + static int lupb_fielddef_getsel(lua_State *L) { const upb_fielddef *f = lupb_fielddef_check(L, 1); upb_selector_t sel; @@ -593,9 +619,11 @@ static const struct luaL_Reg lupb_fielddef_mm[] = { static const struct luaL_Reg lupb_fielddef_m[] = { LUPB_COMMON_DEF_METHODS + {"containing_oneof", lupb_fielddef_containingoneof}, {"containing_type", lupb_fielddef_containingtype}, {"containing_type_name", lupb_fielddef_containingtypename}, {"default", lupb_fielddef_default}, + {"descriptor_type", lupb_fielddef_descriptortype}, {"getsel", lupb_fielddef_getsel}, {"has_subdef", lupb_fielddef_hassubdef}, {"index", lupb_fielddef_index}, @@ -681,6 +709,24 @@ static int lupb_oneofdef_field(lua_State *L) { return 1; } +static int lupb_oneofiter_next(lua_State *L) { + upb_oneof_iter *i = lua_touserdata(L, lua_upvalueindex(1)); + if (upb_oneof_done(i)) return 0; + lupb_fielddef_pushwrapper(L, upb_oneof_iter_field(i), NULL); + upb_oneof_next(i); + return 1; +} + +static int lupb_oneofdef_fields(lua_State *L) { + const upb_oneofdef *o = lupb_oneofdef_check(L, 1); + upb_oneof_iter *i = lua_newuserdata(L, sizeof(upb_oneof_iter)); + upb_oneof_begin(i, o); + /* Need to guarantee that the msgdef outlives the iter. */ + lua_pushvalue(L, 1); + lua_pushcclosure(L, &lupb_oneofiter_next, 2); + return 1; +} + static int lupb_oneofdef_len(lua_State *L) { const upb_oneofdef *o = lupb_oneofdef_check(L, 1); lua_pushinteger(L, upb_oneofdef_numfields(o)); @@ -711,6 +757,7 @@ static int lupb_oneofdef_setname(lua_State *L) { static const struct luaL_Reg lupb_oneofdef_m[] = { {"containing_type", lupb_oneofdef_containingtype}, {"field", lupb_oneofdef_field}, + {"fields", lupb_oneofdef_fields}, {"name", lupb_oneofdef_name}, {"add", lupb_oneofdef_add}, @@ -1008,6 +1055,29 @@ static int lupb_filedef_def(lua_State *L) { return 1; } +static int lupb_filedefdepiter_next(lua_State *L) { + const upb_filedef *f = lupb_filedef_check(L, lua_upvalueindex(1)); + size_t i = lua_tointeger(L, lua_upvalueindex(2)); + + if (i >= upb_filedef_depcount(f)) { + return 0; + } + + lupb_filedef_pushwrapper(L, upb_filedef_dep(f, i), NULL); + lua_pushinteger(L, i + 1); + lua_replace(L, lua_upvalueindex(2)); + return 1; +} + + +static int lupb_filedef_dependencies(lua_State *L) { + lupb_filedef_check(L, 1); + lua_pushvalue(L, 1); + lua_pushnumber(L, 0); /* Index, starts at zero. */ + lua_pushcclosure(L, &lupb_filedefdepiter_next, 2); + return 1; +} + static int lupb_filedef_name(lua_State *L) { const upb_filedef *f = lupb_filedef_check(L, 1); lua_pushstring(L, upb_filedef_name(f)); @@ -1020,6 +1090,12 @@ static int lupb_filedef_package(lua_State *L) { return 1; } +static int lupb_filedef_syntax(lua_State *L) { + const upb_filedef *f = lupb_filedef_check(L, 1); + lua_pushnumber(L, upb_filedef_syntax(f)); + return 1; +} + static int lupb_filedef_len(lua_State *L) { const upb_filedef *f = lupb_filedef_check(L, 1); lua_pushinteger(L, upb_filedef_defcount(f)); @@ -1078,8 +1154,10 @@ static const struct luaL_Reg lupb_filedef_mm[] = { static const struct luaL_Reg lupb_filedef_m[] = { {"def", lupb_filedef_def}, {"defs", lupb_filedef_defs}, + {"dependencies", lupb_filedef_dependencies}, {"name", lupb_filedef_name}, {"package", lupb_filedef_package}, + {"syntax", lupb_filedef_syntax}, {"set_name", lupb_filedef_setname}, {"set_package", lupb_filedef_setpackage}, diff --git a/upb/decode.c b/upb/decode.c new file mode 100644 index 0000000..f28642b --- /dev/null +++ b/upb/decode.c @@ -0,0 +1,385 @@ + +#include "upb/decode.h" + +typedef enum { + UPB_WIRE_TYPE_VARINT = 0, + UPB_WIRE_TYPE_64BIT = 1, + UPB_WIRE_TYPE_DELIMITED = 2, + UPB_WIRE_TYPE_START_GROUP = 3, + UPB_WIRE_TYPE_END_GROUP = 4, + UPB_WIRE_TYPE_32BIT = 5 +} upb_wiretype_t; + +typedef struct { + upb_env *env; + /* Current decoding pointer. Points to the beginning of a field until we + * have finished decoding the whole field. */ + const char *ptr; +} upb_decstate; + +#define CHK(x) if (!(x)) { return false; } + +static void upb_decode_seterr(upb_env *env, const char *msg) { + upb_status status = UPB_STATUS_INIT; + upb_status_seterrmsg(&status, msg); + upb_env_reporterror(env, &status); +} + +static bool upb_decode_varint(const char **ptr, const char *limit, + uint64_t *val) { + uint8_t byte = 0x80; + int bitpos = 0; + const char *p = *ptr; + *val = 0; + + while (byte & 0x80) { + if (bitpos == 70 || p == limit) { + return false; + } + + byte = *p; + *val |= (uint64_t)(byte & 0x7F) << bitpos; + p++; + bitpos += 7; + } + + *ptr = p; + return true; +} + +static bool upb_decode_varint32(const char **ptr, const char *limit, + uint32_t *val) { + uint64_t u64; + if (!upb_decode_varint(ptr, limit, &u64) || u64 > UINT32_MAX) { + return false; + } else { + *val = u64; + return true; + } +} + +static const upb_msglayout_fieldinit_v1 *upb_find_field( + const upb_msglayout_msginit_v1 *l, uint32_t field_number) { + /* Lots of optimization opportunities here. */ + int i; + for (i = 0; i < l->field_count; i++) { + if (l->fields[i].number == field_number) { + return &l->fields[i]; + } + } + + return NULL; /* Unknown field. */ +} + +static bool upb_decode_64bit(const char **ptr, const char *limit, + uint64_t *val) { + if (limit - *ptr < 8) { + return false; + } else { + memcpy(val, *ptr, 8); + *ptr += 8; + return true; + } +} + +static bool upb_decode_32bit(const char **ptr, const char *limit, + uint32_t *val) { + if (limit - *ptr < 4) { + return false; + } else { + memcpy(val, *ptr, 4); + *ptr += 4; + return true; + } +} + +static int32_t upb_zzdec_32(uint32_t n) { + return (n >> 1) ^ -(int32_t)(n & 1); +} + +static int64_t upb_zzdec_64(uint64_t n) { + return (n >> 1) ^ -(int64_t)(n & 1); +} + +static bool upb_decode_string(const char **ptr, const char *limit, + upb_stringview *val) { + uint32_t len; + + if (!upb_decode_varint32(ptr, limit, &len) || + limit - *ptr < len) { + return false; + } + + *val = upb_stringview_make(*ptr, len); + *ptr += len; + return true; +} + +static void upb_set32(void *msg, size_t ofs, uint32_t val) { + memcpy((char*)msg + ofs, &val, sizeof(val)); +} + +static bool upb_append_unknownfield(const char **ptr, const char *start, + const char *limit, char *msg) { + UPB_UNUSED(limit); + UPB_UNUSED(msg); + *ptr = limit; + return true; +} + +static bool upb_decode_unknownfielddata(upb_decstate *d, const char *ptr, + const char *limit, char *msg, + const upb_msglayout_msginit_v1 *l) { + do { + switch (wire_type) { + case UPB_WIRE_TYPE_VARINT: + CHK(upb_decode_varint(&ptr, limit, &val)); + break; + case UPB_WIRE_TYPE_32BIT: + CHK(upb_decode_32bit(&ptr, limit, &val)); + break; + case UPB_WIRE_TYPE_64BIT: + CHK(upb_decode_64bit(&ptr, limit, &val)); + break; + case UPB_WIRE_TYPE_DELIMITED: { + upb_stringview val; + CHK(upb_decode_string(&ptr, limit, &val)); + } + case UPB_WIRE_TYPE_START_GROUP: + depth++; + continue; + case UPB_WIRE_TYPE_END_GROUP: + depth--; + continue; + } + + UPB_ASSERT(depth == 0); + upb_append_unknown(msg, l, d->ptr, ptr); + d->ptr = ptr; + return true; + } while (true); +} + +static bool upb_decode_field(upb_decstate *d, const char *limit, char *msg, + const upb_msglayout_msginit_v1 *l) { + uint32_t tag; + uint32_t wire_type; + uint32_t field_number; + const char *ptr = d->ptr; + const upb_msglayout_fieldinit_v1 *f; + + if (!upb_decode_varint32(&ptr, limit, &tag)) { + upb_decode_seterr(env, "Error decoding tag.\n"); + return false; + } + + wire_type = tag & 0x7; + field_number = tag >> 3; + + if (field_number == 0) { + return false; + } + + f = upb_find_field(l, field_number); + + if (f) { + return upb_decode_knownfield(d, ptr, limit, msg, l, f); + } else { + return upb_decode_unknownfield(d, ptr, limit, msg, l); + } + + if (f->label == UPB_LABEL_REPEATED) { + arr = upb_getarray(msg, f, env); + } + + switch (wire_type) { + case UPB_WIRE_TYPE_VARINT: { + uint64_t val; + if (!upb_decode_varint(&ptr, limit, &val)) { + upb_decode_seterr(env, "Error decoding varint value.\n"); + return false; + } + + if (!f) { + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + if (f->label == UPB_LABEL_REPEATED) { + upb_array *arr = upb_getarray(msg, f, env); + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_INT64: + case UPB_DESCRIPTOR_TYPE_UINT64: + memcpy(arr->data, &val, sizeof(val)); + arr->len++; + break; + case UPB_DESCRIPTOR_TYPE_INT32: + case UPB_DESCRIPTOR_TYPE_UINT32: + case UPB_DESCRIPTOR_TYPE_ENUM: { + uint32_t val32 = val; + memcpy(arr->data, &val32, sizeof(val32)); + arr->len++; + break; + } + case UPB_DESCRIPTOR_TYPE_SINT32: { + int32_t decoded = upb_zzdec_32(val); + memcpy(arr->data, &decoded, sizeof(decoded)); + arr->len++; + break; + } + case UPB_DESCRIPTOR_TYPE_SINT64: { + int64_t decoded = upb_zzdec_64(val); + memcpy(arr->data, &decoded, sizeof(decoded)); + arr->len++; + break; + } + default: + return upb_append_unknown(ptr, field_start, ptr, msg); + } + } else { + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_INT64: + case UPB_DESCRIPTOR_TYPE_UINT64: + memcpy(msg + f->offset, &val, sizeof(val)); + break; + case UPB_DESCRIPTOR_TYPE_INT32: + case UPB_DESCRIPTOR_TYPE_UINT32: + case UPB_DESCRIPTOR_TYPE_ENUM: { + uint32_t val32 = val; + memcpy(msg + f->offset, &val32, sizeof(val32)); + break; + } + case UPB_DESCRIPTOR_TYPE_SINT32: { + int32_t decoded = upb_zzdec_32(val); + memcpy(msg + f->offset, &decoded, sizeof(decoded)); + break; + } + case UPB_DESCRIPTOR_TYPE_SINT64: { + int64_t decoded = upb_zzdec_64(val); + memcpy(msg + f->offset, &decoded, sizeof(decoded)); + break; + } + default: + return upb_append_unknown(ptr, field_start, ptr, msg); + } + } + + break; + } + case UPB_WIRE_TYPE_64BIT: { + uint64_t val; + if (!upb_decode_64bit(&ptr, limit, &val)) { + upb_decode_seterr(env, "Error decoding 64bit value.\n"); + return false; + } + + if (!f) { + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_DOUBLE: + case UPB_DESCRIPTOR_TYPE_FIXED64: + case UPB_DESCRIPTOR_TYPE_SFIXED64: + memcpy(msg + f->offset, &val, sizeof(val)); + default: + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + break; + } + case UPB_WIRE_TYPE_32BIT: { + uint32_t val; + if (!upb_decode_32bit(&ptr, limit, &val)) { + upb_decode_seterr(env, "Error decoding 32bit value.\n"); + return false; + } + + if (!f) { + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_FLOAT: + case UPB_DESCRIPTOR_TYPE_FIXED32: + case UPB_DESCRIPTOR_TYPE_SFIXED32: + memcpy(msg + f->offset, &val, sizeof(val)); + default: + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + break; + } + case UPB_WIRE_TYPE_DELIMITED: { + upb_stringview val; + if (!upb_decode_string(&ptr, limit, &val)) { + upb_decode_seterr(env, "Error decoding delimited value.\n"); + return false; + } + + if (!f) { + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_STRING: + case UPB_DESCRIPTOR_TYPE_BYTES: + memcpy(msg + f->offset, &val, sizeof(val)); + break; + case UPB_DESCRIPTOR_TYPE_INT64: + case UPB_DESCRIPTOR_TYPE_UINT64: { + memcpy(msg + f->offset, &val, sizeof(val)); + break; + case UPB_DESCRIPTOR_TYPE_INT32: + case UPB_DESCRIPTOR_TYPE_UINT32: + case UPB_DESCRIPTOR_TYPE_ENUM: { + uint32_t val32 = val; + memcpy(msg + f->offset, &val32, sizeof(val32)); + break; + } + case UPB_DESCRIPTOR_TYPE_SINT32: { + int32_t decoded = upb_zzdec_32(val); + memcpy(msg + f->offset, &decoded, sizeof(decoded)); + break; + } + case UPB_DESCRIPTOR_TYPE_SINT64: + case UPB_DESCRIPTOR_TYPE_FLOAT: + case UPB_DESCRIPTOR_TYPE_FIXED32: + case UPB_DESCRIPTOR_TYPE_SFIXED32: + /* + case UPB_DESCRIPTOR_TYPE_MESSAGE: { + upb_decode_message(val, + } + */ + default: + return upb_append_unknown(ptr, field_start, ptr, msg); + } + + break; + } + } + + if (f->oneof_index != UPB_NOT_IN_ONEOF) { + upb_set32(msg, l->oneofs[f->oneof_index].case_offset, f->number); + } + + d->ptr = ptr; + return true; +} + +static bool upb_decode_message(upb_decstate *d, upb_stringview buf, + char *msg, const upb_msglayout_msginit_v1 *l) { + const char *limit = ptr + buf.size; + + while (d->ptr < limit) { + if (!upb_decode_field(&ptr, limit, msg, l, env)) { + return false; + } + } + + return true; +} + +bool upb_decode(upb_stringview buf, void *msg, + const upb_msglayout_msginit_v1 *l, upb_env *env) { + return upb_decode_message(buf, msg, l, env); +} diff --git a/upb/decode.h b/upb/decode.h new file mode 100644 index 0000000..2a9e39e --- /dev/null +++ b/upb/decode.h @@ -0,0 +1,17 @@ +/* +** upb_decode: parsing into a upb_msg using a upb_msglayout. +*/ + +#ifndef UPB_DECODE_H_ +#define UPB_DECODE_H_ + +#include "upb/msg.h" + +UPB_BEGIN_EXTERN_C + +bool upb_decode(upb_stringview buf, void *msg, + const upb_msglayout_msginit_v1 *l, upb_env *env); + +UPB_END_EXTERN_C + +#endif /* UPB_DECODE_H_ */ diff --git a/upb/descriptor/descriptor.upb.c b/upb/descriptor/descriptor.upb.c new file mode 100644 index 0000000..c0b537c --- /dev/null +++ b/upb/descriptor/descriptor.upb.c @@ -0,0 +1,1611 @@ +/* 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. */ + +#include <stddef.h> +#include "upb/msg.h" +#include "upb/upb.h" +#include "upb/descriptor/descriptor.upb.h" + + +struct google_protobuf_FileDescriptorSet { + upb_array* file; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorSet_submsgs[1] = { + &google_protobuf_FileDescriptorProto_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_FileDescriptorSet__fields[1] = { + {1, offsetof(google_protobuf_FileDescriptorSet, file), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorSet_msginit = { + &google_protobuf_FileDescriptorSet_submsgs[0], + &google_protobuf_FileDescriptorSet__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_FileDescriptorSet), 1, 0, false, true +}; + +google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_env *env) { + google_protobuf_FileDescriptorSet *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_FileDescriptorSet_serialize(google_protobuf_FileDescriptorSet *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg) { + return msg->file; +} +void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value) { + msg->file = value; +} +struct google_protobuf_FileDescriptorProto { + upb_stringview name; + upb_stringview package; + upb_stringview syntax; + google_protobuf_FileOptions* options; + google_protobuf_SourceCodeInfo* source_code_info; + upb_array* dependency; + upb_array* message_type; + upb_array* enum_type; + upb_array* service; + upb_array* extension; + upb_array* public_dependency; + upb_array* weak_dependency; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorProto_submsgs[6] = { + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_FileOptions_msginit, + &google_protobuf_ServiceDescriptorProto_msginit, + &google_protobuf_SourceCodeInfo_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_FileDescriptorProto__fields[12] = { + {1, offsetof(google_protobuf_FileDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_FileDescriptorProto, package), 1, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {3, offsetof(google_protobuf_FileDescriptorProto, dependency), -1, UPB_NOT_IN_ONEOF, -1, 9, 3}, + {4, offsetof(google_protobuf_FileDescriptorProto, message_type), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, + {5, offsetof(google_protobuf_FileDescriptorProto, enum_type), -1, UPB_NOT_IN_ONEOF, 1, 11, 3}, + {6, offsetof(google_protobuf_FileDescriptorProto, service), -1, UPB_NOT_IN_ONEOF, 4, 11, 3}, + {7, offsetof(google_protobuf_FileDescriptorProto, extension), -1, UPB_NOT_IN_ONEOF, 2, 11, 3}, + {8, offsetof(google_protobuf_FileDescriptorProto, options), 3, UPB_NOT_IN_ONEOF, 3, 11, 1}, + {9, offsetof(google_protobuf_FileDescriptorProto, source_code_info), 4, UPB_NOT_IN_ONEOF, 5, 11, 1}, + {10, offsetof(google_protobuf_FileDescriptorProto, public_dependency), -1, UPB_NOT_IN_ONEOF, -1, 5, 3}, + {11, offsetof(google_protobuf_FileDescriptorProto, weak_dependency), -1, UPB_NOT_IN_ONEOF, -1, 5, 3}, + {12, offsetof(google_protobuf_FileDescriptorProto, syntax), 2, UPB_NOT_IN_ONEOF, -1, 9, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorProto_msginit = { + &google_protobuf_FileDescriptorProto_submsgs[0], + &google_protobuf_FileDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_FileDescriptorProto), 12, 0, false, true +}; + +google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_env *env) { + google_protobuf_FileDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_FileDescriptorProto_serialize(google_protobuf_FileDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { + return msg->package; +} +void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { + msg->package = value; +} +upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg) { + return msg->dependency; +} +void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->dependency = value; +} +upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg) { + return msg->message_type; +} +void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->message_type = value; +} +upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg) { + return msg->enum_type; +} +void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->enum_type = value; +} +upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg) { + return msg->service; +} +void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->service = value; +} +upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg) { + return msg->extension; +} +void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->extension = value; +} +google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { + return msg->options; +} +void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { + msg->options = value; +} +google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { + return msg->source_code_info; +} +void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { + msg->source_code_info = value; +} +upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg) { + return msg->public_dependency; +} +void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->public_dependency = value; +} +upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg) { + return msg->weak_dependency; +} +void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { + msg->weak_dependency = value; +} +upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { + return msg->syntax; +} +void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { + msg->syntax = value; +} +struct google_protobuf_DescriptorProto { + upb_stringview name; + google_protobuf_MessageOptions* options; + upb_array* field; + upb_array* nested_type; + upb_array* enum_type; + upb_array* extension_range; + upb_array* extension; + upb_array* oneof_decl; + upb_array* reserved_range; + upb_array* reserved_name; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_submsgs[8] = { + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_DescriptorProto_ExtensionRange_msginit, + &google_protobuf_DescriptorProto_ReservedRange_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_MessageOptions_msginit, + &google_protobuf_OneofDescriptorProto_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto__fields[10] = { + {1, offsetof(google_protobuf_DescriptorProto, name), 0, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_DescriptorProto, field), -1, UPB_NOT_IN_ONEOF, 4, 11, 3}, + {3, offsetof(google_protobuf_DescriptorProto, nested_type), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, + {4, offsetof(google_protobuf_DescriptorProto, enum_type), -1, UPB_NOT_IN_ONEOF, 3, 11, 3}, + {5, offsetof(google_protobuf_DescriptorProto, extension_range), -1, UPB_NOT_IN_ONEOF, 1, 11, 3}, + {6, offsetof(google_protobuf_DescriptorProto, extension), -1, UPB_NOT_IN_ONEOF, 4, 11, 3}, + {7, offsetof(google_protobuf_DescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 5, 11, 1}, + {8, offsetof(google_protobuf_DescriptorProto, oneof_decl), -1, UPB_NOT_IN_ONEOF, 6, 11, 3}, + {9, offsetof(google_protobuf_DescriptorProto, reserved_range), -1, UPB_NOT_IN_ONEOF, 2, 11, 3}, + {10, offsetof(google_protobuf_DescriptorProto, reserved_name), -1, UPB_NOT_IN_ONEOF, -1, 9, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_msginit = { + &google_protobuf_DescriptorProto_submsgs[0], + &google_protobuf_DescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto), 10, 0, false, true +}; + +google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_env *env) { + google_protobuf_DescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_DescriptorProto_serialize(google_protobuf_DescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { + return msg->name; +} +void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg) { + return msg->field; +} +void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->field = value; +} +upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg) { + return msg->nested_type; +} +void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->nested_type = value; +} +upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg) { + return msg->enum_type; +} +void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->enum_type = value; +} +upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg) { + return msg->extension_range; +} +void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->extension_range = value; +} +upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg) { + return msg->extension; +} +void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->extension = value; +} +google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { + return msg->options; +} +void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { + msg->options = value; +} +upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg) { + return msg->oneof_decl; +} +void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->oneof_decl = value; +} +upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg) { + return msg->reserved_range; +} +void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->reserved_range = value; +} +upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg) { + return msg->reserved_name; +} +void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value) { + msg->reserved_name = value; +} +struct google_protobuf_DescriptorProto_ExtensionRange { + int32_t start; + int32_t end; +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto_ExtensionRange__fields[2] = { + {1, offsetof(google_protobuf_DescriptorProto_ExtensionRange, start), 0, UPB_NOT_IN_ONEOF, -1, 5, 1}, + {2, offsetof(google_protobuf_DescriptorProto_ExtensionRange, end), 1, UPB_NOT_IN_ONEOF, -1, 5, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ExtensionRange_msginit = { + NULL, + &google_protobuf_DescriptorProto_ExtensionRange__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto_ExtensionRange), 2, 0, false, true +}; + +google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_env *env) { + google_protobuf_DescriptorProto_ExtensionRange *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_DescriptorProto_ExtensionRange_serialize(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { + return msg->start; +} +void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { + msg->start = value; +} +int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { + return msg->end; +} +void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { + msg->end = value; +} +struct google_protobuf_DescriptorProto_ReservedRange { + int32_t start; + int32_t end; +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto_ReservedRange__fields[2] = { + {1, offsetof(google_protobuf_DescriptorProto_ReservedRange, start), 0, UPB_NOT_IN_ONEOF, -1, 5, 1}, + {2, offsetof(google_protobuf_DescriptorProto_ReservedRange, end), 1, UPB_NOT_IN_ONEOF, -1, 5, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ReservedRange_msginit = { + NULL, + &google_protobuf_DescriptorProto_ReservedRange__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto_ReservedRange), 2, 0, false, true +}; + +google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_env *env) { + google_protobuf_DescriptorProto_ReservedRange *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_DescriptorProto_ReservedRange_serialize(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { + return msg->start; +} +void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { + msg->start = value; +} +int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { + return msg->end; +} +void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { + msg->end = value; +} +struct google_protobuf_FieldDescriptorProto { + google_protobuf_FieldDescriptorProto_Label label; + google_protobuf_FieldDescriptorProto_Type type; + int32_t number; + int32_t oneof_index; + upb_stringview name; + upb_stringview extendee; + upb_stringview type_name; + upb_stringview default_value; + upb_stringview json_name; + google_protobuf_FieldOptions* options; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_FieldDescriptorProto_submsgs[1] = { + &google_protobuf_FieldOptions_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_FieldDescriptorProto__fields[10] = { + {1, offsetof(google_protobuf_FieldDescriptorProto, name), 4, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_FieldDescriptorProto, extendee), 5, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {3, offsetof(google_protobuf_FieldDescriptorProto, number), 2, UPB_NOT_IN_ONEOF, -1, 5, 1}, + {4, offsetof(google_protobuf_FieldDescriptorProto, label), 0, UPB_NOT_IN_ONEOF, -1, 14, 1}, + {5, offsetof(google_protobuf_FieldDescriptorProto, type), 1, UPB_NOT_IN_ONEOF, -1, 14, 1}, + {6, offsetof(google_protobuf_FieldDescriptorProto, type_name), 6, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {7, offsetof(google_protobuf_FieldDescriptorProto, default_value), 7, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {8, offsetof(google_protobuf_FieldDescriptorProto, options), 9, UPB_NOT_IN_ONEOF, 0, 11, 1}, + {9, offsetof(google_protobuf_FieldDescriptorProto, oneof_index), 3, UPB_NOT_IN_ONEOF, -1, 5, 1}, + {10, offsetof(google_protobuf_FieldDescriptorProto, json_name), 8, UPB_NOT_IN_ONEOF, -1, 9, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_FieldDescriptorProto_msginit = { + &google_protobuf_FieldDescriptorProto_submsgs[0], + &google_protobuf_FieldDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_FieldDescriptorProto), 10, 0, false, true +}; + +google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_env *env) { + google_protobuf_FieldDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_FieldDescriptorProto_serialize(google_protobuf_FieldDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { + return msg->extendee; +} +void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { + msg->extendee = value; +} +int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { + return msg->number; +} +void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { + msg->number = value; +} +google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { + return msg->label; +} +void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) { + msg->label = value; +} +google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { + return msg->type; +} +void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) { + msg->type = value; +} +upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { + return msg->type_name; +} +void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { + msg->type_name = value; +} +upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { + return msg->default_value; +} +void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { + msg->default_value = value; +} +google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { + return msg->options; +} +void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { + msg->options = value; +} +int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { + return msg->oneof_index; +} +void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { + msg->oneof_index = value; +} +upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { + return msg->json_name; +} +void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { + msg->json_name = value; +} +struct google_protobuf_OneofDescriptorProto { + upb_stringview name; +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_OneofDescriptorProto__fields[1] = { + {1, offsetof(google_protobuf_OneofDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, -1, 9, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_OneofDescriptorProto_msginit = { + NULL, + &google_protobuf_OneofDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_OneofDescriptorProto), 1, 0, false, true +}; + +google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_env *env) { + google_protobuf_OneofDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_OneofDescriptorProto_serialize(google_protobuf_OneofDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +struct google_protobuf_EnumDescriptorProto { + upb_stringview name; + google_protobuf_EnumOptions* options; + upb_array* value; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_EnumDescriptorProto_submsgs[2] = { + &google_protobuf_EnumOptions_msginit, + &google_protobuf_EnumValueDescriptorProto_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_EnumDescriptorProto__fields[3] = { + {1, offsetof(google_protobuf_EnumDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_EnumDescriptorProto, value), -1, UPB_NOT_IN_ONEOF, 1, 11, 3}, + {3, offsetof(google_protobuf_EnumDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 0, 11, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_msginit = { + &google_protobuf_EnumDescriptorProto_submsgs[0], + &google_protobuf_EnumDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_EnumDescriptorProto), 3, 0, false, true +}; + +google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_env *env) { + google_protobuf_EnumDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_EnumDescriptorProto_serialize(google_protobuf_EnumDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg) { + return msg->value; +} +void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { + msg->value = value; +} +google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { + return msg->options; +} +void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { + msg->options = value; +} +struct google_protobuf_EnumValueDescriptorProto { + int32_t number; + upb_stringview name; + google_protobuf_EnumValueOptions* options; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { + &google_protobuf_EnumValueOptions_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_EnumValueDescriptorProto__fields[3] = { + {1, offsetof(google_protobuf_EnumValueDescriptorProto, name), 1, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_EnumValueDescriptorProto, number), 0, UPB_NOT_IN_ONEOF, -1, 5, 1}, + {3, offsetof(google_protobuf_EnumValueDescriptorProto, options), 2, UPB_NOT_IN_ONEOF, 0, 11, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_EnumValueDescriptorProto_msginit = { + &google_protobuf_EnumValueDescriptorProto_submsgs[0], + &google_protobuf_EnumValueDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_EnumValueDescriptorProto), 3, 0, false, true +}; + +google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_env *env) { + google_protobuf_EnumValueDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_EnumValueDescriptorProto_serialize(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { + return msg->number; +} +void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { + msg->number = value; +} +google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { + return msg->options; +} +void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { + msg->options = value; +} +struct google_protobuf_ServiceDescriptorProto { + upb_stringview name; + google_protobuf_ServiceOptions* options; + upb_array* method; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { + &google_protobuf_MethodDescriptorProto_msginit, + &google_protobuf_ServiceOptions_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_ServiceDescriptorProto__fields[3] = { + {1, offsetof(google_protobuf_ServiceDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_ServiceDescriptorProto, method), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, + {3, offsetof(google_protobuf_ServiceDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 1, 11, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_ServiceDescriptorProto_msginit = { + &google_protobuf_ServiceDescriptorProto_submsgs[0], + &google_protobuf_ServiceDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_ServiceDescriptorProto), 3, 0, false, true +}; + +google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_env *env) { + google_protobuf_ServiceDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_ServiceDescriptorProto_serialize(google_protobuf_ServiceDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg) { + return msg->method; +} +void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value) { + msg->method = value; +} +google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { + return msg->options; +} +void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { + msg->options = value; +} +struct google_protobuf_MethodDescriptorProto { + bool client_streaming; + bool server_streaming; + upb_stringview name; + upb_stringview input_type; + upb_stringview output_type; + google_protobuf_MethodOptions* options; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_MethodDescriptorProto_submsgs[1] = { + &google_protobuf_MethodOptions_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_MethodDescriptorProto__fields[6] = { + {1, offsetof(google_protobuf_MethodDescriptorProto, name), 2, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {2, offsetof(google_protobuf_MethodDescriptorProto, input_type), 3, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {3, offsetof(google_protobuf_MethodDescriptorProto, output_type), 4, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {4, offsetof(google_protobuf_MethodDescriptorProto, options), 5, UPB_NOT_IN_ONEOF, 0, 11, 1}, + {5, offsetof(google_protobuf_MethodDescriptorProto, client_streaming), 0, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {6, offsetof(google_protobuf_MethodDescriptorProto, server_streaming), 1, UPB_NOT_IN_ONEOF, -1, 8, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_MethodDescriptorProto_msginit = { + &google_protobuf_MethodDescriptorProto_submsgs[0], + &google_protobuf_MethodDescriptorProto__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_MethodDescriptorProto), 6, 0, false, true +}; + +google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_env *env) { + google_protobuf_MethodDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_MethodDescriptorProto_serialize(google_protobuf_MethodDescriptorProto *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { + return msg->name; +} +void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { + msg->name = value; +} +upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { + return msg->input_type; +} +void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { + msg->input_type = value; +} +upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { + return msg->output_type; +} +void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { + msg->output_type = value; +} +google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { + return msg->options; +} +void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { + msg->options = value; +} +bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { + return msg->client_streaming; +} +void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { + msg->client_streaming = value; +} +bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { + return msg->server_streaming; +} +void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { + msg->server_streaming = value; +} +struct google_protobuf_FileOptions { + google_protobuf_FileOptions_OptimizeMode optimize_for; + bool java_multiple_files; + bool cc_generic_services; + bool java_generic_services; + bool py_generic_services; + bool java_generate_equals_and_hash; + bool deprecated; + bool java_string_check_utf8; + bool cc_enable_arenas; + bool javanano_use_deprecated_package; + upb_stringview java_package; + upb_stringview java_outer_classname; + upb_stringview go_package; + upb_stringview objc_class_prefix; + upb_stringview csharp_namespace; + upb_stringview php_class_prefix; + upb_stringview php_namespace; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_FileOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_FileOptions__fields[18] = { + {1, offsetof(google_protobuf_FileOptions, java_package), 10, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {8, offsetof(google_protobuf_FileOptions, java_outer_classname), 11, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {9, offsetof(google_protobuf_FileOptions, optimize_for), 0, UPB_NOT_IN_ONEOF, -1, 14, 1}, + {10, offsetof(google_protobuf_FileOptions, java_multiple_files), 1, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {11, offsetof(google_protobuf_FileOptions, go_package), 12, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {16, offsetof(google_protobuf_FileOptions, cc_generic_services), 2, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {17, offsetof(google_protobuf_FileOptions, java_generic_services), 3, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {18, offsetof(google_protobuf_FileOptions, py_generic_services), 4, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {20, offsetof(google_protobuf_FileOptions, java_generate_equals_and_hash), 5, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {23, offsetof(google_protobuf_FileOptions, deprecated), 6, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {27, offsetof(google_protobuf_FileOptions, java_string_check_utf8), 7, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {31, offsetof(google_protobuf_FileOptions, cc_enable_arenas), 8, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {36, offsetof(google_protobuf_FileOptions, objc_class_prefix), 13, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {37, offsetof(google_protobuf_FileOptions, csharp_namespace), 14, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {38, offsetof(google_protobuf_FileOptions, javanano_use_deprecated_package), 9, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {40, offsetof(google_protobuf_FileOptions, php_class_prefix), 15, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {41, offsetof(google_protobuf_FileOptions, php_namespace), 16, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {999, offsetof(google_protobuf_FileOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_FileOptions_msginit = { + &google_protobuf_FileOptions_submsgs[0], + &google_protobuf_FileOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_FileOptions), 18, 0, false, true +}; + +google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_env *env) { + google_protobuf_FileOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_FileOptions_serialize(google_protobuf_FileOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { + return msg->java_package; +} +void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->java_package = value; +} +upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { + return msg->java_outer_classname; +} +void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->java_outer_classname = value; +} +google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { + return msg->optimize_for; +} +void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) { + msg->optimize_for = value; +} +bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { + return msg->java_multiple_files; +} +void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { + msg->java_multiple_files = value; +} +upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { + return msg->go_package; +} +void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->go_package = value; +} +bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { + return msg->cc_generic_services; +} +void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { + msg->cc_generic_services = value; +} +bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { + return msg->java_generic_services; +} +void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { + msg->java_generic_services = value; +} +bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { + return msg->py_generic_services; +} +void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { + msg->py_generic_services = value; +} +bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { + return msg->java_generate_equals_and_hash; +} +void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { + msg->java_generate_equals_and_hash = value; +} +bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { + return msg->deprecated; +} +void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { + msg->deprecated = value; +} +bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { + return msg->java_string_check_utf8; +} +void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { + msg->java_string_check_utf8 = value; +} +bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { + return msg->cc_enable_arenas; +} +void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { + msg->cc_enable_arenas = value; +} +upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { + return msg->objc_class_prefix; +} +void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->objc_class_prefix = value; +} +upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { + return msg->csharp_namespace; +} +void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->csharp_namespace = value; +} +bool google_protobuf_FileOptions_javanano_use_deprecated_package(const google_protobuf_FileOptions *msg) { + return msg->javanano_use_deprecated_package; +} +void google_protobuf_FileOptions_set_javanano_use_deprecated_package(google_protobuf_FileOptions *msg, bool value) { + msg->javanano_use_deprecated_package = value; +} +upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { + return msg->php_class_prefix; +} +void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->php_class_prefix = value; +} +upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { + return msg->php_namespace; +} +void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { + msg->php_namespace = value; +} +upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_MessageOptions { + bool message_set_wire_format; + bool no_standard_descriptor_accessor; + bool deprecated; + bool map_entry; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_MessageOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_MessageOptions__fields[5] = { + {1, offsetof(google_protobuf_MessageOptions, message_set_wire_format), 0, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {2, offsetof(google_protobuf_MessageOptions, no_standard_descriptor_accessor), 1, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {3, offsetof(google_protobuf_MessageOptions, deprecated), 2, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {7, offsetof(google_protobuf_MessageOptions, map_entry), 3, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {999, offsetof(google_protobuf_MessageOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_MessageOptions_msginit = { + &google_protobuf_MessageOptions_submsgs[0], + &google_protobuf_MessageOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_MessageOptions), 5, 0, false, true +}; + +google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_env *env) { + google_protobuf_MessageOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_MessageOptions_serialize(google_protobuf_MessageOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { + return msg->message_set_wire_format; +} +void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { + msg->message_set_wire_format = value; +} +bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { + return msg->no_standard_descriptor_accessor; +} +void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { + msg->no_standard_descriptor_accessor = value; +} +bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { + return msg->deprecated; +} +void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { + msg->deprecated = value; +} +bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { + return msg->map_entry; +} +void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { + msg->map_entry = value; +} +upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_FieldOptions { + google_protobuf_FieldOptions_CType ctype; + google_protobuf_FieldOptions_JSType jstype; + bool packed; + bool deprecated; + bool lazy; + bool weak; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_FieldOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_FieldOptions__fields[7] = { + {1, offsetof(google_protobuf_FieldOptions, ctype), 0, UPB_NOT_IN_ONEOF, -1, 14, 1}, + {2, offsetof(google_protobuf_FieldOptions, packed), 2, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {3, offsetof(google_protobuf_FieldOptions, deprecated), 3, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {5, offsetof(google_protobuf_FieldOptions, lazy), 4, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {6, offsetof(google_protobuf_FieldOptions, jstype), 1, UPB_NOT_IN_ONEOF, -1, 14, 1}, + {10, offsetof(google_protobuf_FieldOptions, weak), 5, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {999, offsetof(google_protobuf_FieldOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_FieldOptions_msginit = { + &google_protobuf_FieldOptions_submsgs[0], + &google_protobuf_FieldOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_FieldOptions), 7, 0, false, true +}; + +google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_env *env) { + google_protobuf_FieldOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_FieldOptions_serialize(google_protobuf_FieldOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { + return msg->ctype; +} +void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) { + msg->ctype = value; +} +bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { + return msg->packed; +} +void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { + msg->packed = value; +} +bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { + return msg->deprecated; +} +void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { + msg->deprecated = value; +} +bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { + return msg->lazy; +} +void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { + msg->lazy = value; +} +google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { + return msg->jstype; +} +void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) { + msg->jstype = value; +} +bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { + return msg->weak; +} +void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { + msg->weak = value; +} +upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_EnumOptions { + bool allow_alias; + bool deprecated; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_EnumOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_EnumOptions__fields[3] = { + {2, offsetof(google_protobuf_EnumOptions, allow_alias), 0, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {3, offsetof(google_protobuf_EnumOptions, deprecated), 1, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {999, offsetof(google_protobuf_EnumOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_EnumOptions_msginit = { + &google_protobuf_EnumOptions_submsgs[0], + &google_protobuf_EnumOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_EnumOptions), 3, 0, false, true +}; + +google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_env *env) { + google_protobuf_EnumOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_EnumOptions_serialize(google_protobuf_EnumOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { + return msg->allow_alias; +} +void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { + msg->allow_alias = value; +} +bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { + return msg->deprecated; +} +void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { + msg->deprecated = value; +} +upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_EnumValueOptions { + bool deprecated; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_EnumValueOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_EnumValueOptions__fields[2] = { + {1, offsetof(google_protobuf_EnumValueOptions, deprecated), 0, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {999, offsetof(google_protobuf_EnumValueOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_EnumValueOptions_msginit = { + &google_protobuf_EnumValueOptions_submsgs[0], + &google_protobuf_EnumValueOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_EnumValueOptions), 2, 0, false, true +}; + +google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_env *env) { + google_protobuf_EnumValueOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_EnumValueOptions_serialize(google_protobuf_EnumValueOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { + return msg->deprecated; +} +void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { + msg->deprecated = value; +} +upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_ServiceOptions { + bool deprecated; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_ServiceOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_ServiceOptions__fields[2] = { + {33, offsetof(google_protobuf_ServiceOptions, deprecated), 0, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {999, offsetof(google_protobuf_ServiceOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_ServiceOptions_msginit = { + &google_protobuf_ServiceOptions_submsgs[0], + &google_protobuf_ServiceOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_ServiceOptions), 2, 0, false, true +}; + +google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_env *env) { + google_protobuf_ServiceOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_ServiceOptions_serialize(google_protobuf_ServiceOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { + return msg->deprecated; +} +void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { + msg->deprecated = value; +} +upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_MethodOptions { + bool deprecated; + upb_array* uninterpreted_option; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_MethodOptions_submsgs[1] = { + &google_protobuf_UninterpretedOption_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_MethodOptions__fields[2] = { + {33, offsetof(google_protobuf_MethodOptions, deprecated), 0, UPB_NOT_IN_ONEOF, -1, 8, 1}, + {999, offsetof(google_protobuf_MethodOptions, uninterpreted_option), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_MethodOptions_msginit = { + &google_protobuf_MethodOptions_submsgs[0], + &google_protobuf_MethodOptions__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_MethodOptions), 2, 0, false, true +}; + +google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_env *env) { + google_protobuf_MethodOptions *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_MethodOptions_serialize(google_protobuf_MethodOptions *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { + return msg->deprecated; +} +void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { + msg->deprecated = value; +} +upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg) { + return msg->uninterpreted_option; +} +void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value) { + msg->uninterpreted_option = value; +} +struct google_protobuf_UninterpretedOption { + uint64_t positive_int_value; + int64_t negative_int_value; + double double_value; + upb_stringview identifier_value; + upb_stringview string_value; + upb_stringview aggregate_value; + upb_array* name; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_UninterpretedOption_submsgs[1] = { + &google_protobuf_UninterpretedOption_NamePart_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_UninterpretedOption__fields[7] = { + {2, offsetof(google_protobuf_UninterpretedOption, name), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, + {3, offsetof(google_protobuf_UninterpretedOption, identifier_value), 3, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {4, offsetof(google_protobuf_UninterpretedOption, positive_int_value), 0, UPB_NOT_IN_ONEOF, -1, 4, 1}, + {5, offsetof(google_protobuf_UninterpretedOption, negative_int_value), 1, UPB_NOT_IN_ONEOF, -1, 3, 1}, + {6, offsetof(google_protobuf_UninterpretedOption, double_value), 2, UPB_NOT_IN_ONEOF, -1, 1, 1}, + {7, offsetof(google_protobuf_UninterpretedOption, string_value), 4, UPB_NOT_IN_ONEOF, -1, 12, 1}, + {8, offsetof(google_protobuf_UninterpretedOption, aggregate_value), 5, UPB_NOT_IN_ONEOF, -1, 9, 1}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_msginit = { + &google_protobuf_UninterpretedOption_submsgs[0], + &google_protobuf_UninterpretedOption__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_UninterpretedOption), 7, 0, false, true +}; + +google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_env *env) { + google_protobuf_UninterpretedOption *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_UninterpretedOption_serialize(google_protobuf_UninterpretedOption *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg) { + return msg->name; +} +void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value) { + msg->name = value; +} +upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { + return msg->identifier_value; +} +void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { + msg->identifier_value = value; +} +uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { + return msg->positive_int_value; +} +void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { + msg->positive_int_value = value; +} +int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { + return msg->negative_int_value; +} +void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { + msg->negative_int_value = value; +} +double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { + return msg->double_value; +} +void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { + msg->double_value = value; +} +upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { + return msg->string_value; +} +void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { + msg->string_value = value; +} +upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { + return msg->aggregate_value; +} +void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { + msg->aggregate_value = value; +} +struct google_protobuf_UninterpretedOption_NamePart { + bool is_extension; + upb_stringview name_part; +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_UninterpretedOption_NamePart__fields[2] = { + {1, offsetof(google_protobuf_UninterpretedOption_NamePart, name_part), 1, UPB_NOT_IN_ONEOF, -1, 9, 2}, + {2, offsetof(google_protobuf_UninterpretedOption_NamePart, is_extension), 0, UPB_NOT_IN_ONEOF, -1, 8, 2}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_NamePart_msginit = { + NULL, + &google_protobuf_UninterpretedOption_NamePart__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_UninterpretedOption_NamePart), 2, 0, false, true +}; + +google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_env *env) { + google_protobuf_UninterpretedOption_NamePart *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_UninterpretedOption_NamePart_serialize(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { + return msg->name_part; +} +void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value) { + msg->name_part = value; +} +bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { + return msg->is_extension; +} +void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { + msg->is_extension = value; +} +struct google_protobuf_SourceCodeInfo { + upb_array* location; +}; + +static const upb_msglayout_msginit_v1 *const google_protobuf_SourceCodeInfo_submsgs[1] = { + &google_protobuf_SourceCodeInfo_Location_msginit, +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_SourceCodeInfo__fields[1] = { + {1, offsetof(google_protobuf_SourceCodeInfo, location), -1, UPB_NOT_IN_ONEOF, 0, 11, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_msginit = { + &google_protobuf_SourceCodeInfo_submsgs[0], + &google_protobuf_SourceCodeInfo__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_SourceCodeInfo), 1, 0, false, true +}; + +google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_env *env) { + google_protobuf_SourceCodeInfo *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_SourceCodeInfo_serialize(google_protobuf_SourceCodeInfo *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg) { + return msg->location; +} +void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value) { + msg->location = value; +} +struct google_protobuf_SourceCodeInfo_Location { + upb_stringview leading_comments; + upb_stringview trailing_comments; + upb_array* path; + upb_array* span; + upb_array* leading_detached_comments; +}; + +static const upb_msglayout_fieldinit_v1 google_protobuf_SourceCodeInfo_Location__fields[5] = { + {1, offsetof(google_protobuf_SourceCodeInfo_Location, path), -1, UPB_NOT_IN_ONEOF, -1, 5, 3}, + {2, offsetof(google_protobuf_SourceCodeInfo_Location, span), -1, UPB_NOT_IN_ONEOF, -1, 5, 3}, + {3, offsetof(google_protobuf_SourceCodeInfo_Location, leading_comments), 0, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {4, offsetof(google_protobuf_SourceCodeInfo_Location, trailing_comments), 1, UPB_NOT_IN_ONEOF, -1, 9, 1}, + {6, offsetof(google_protobuf_SourceCodeInfo_Location, leading_detached_comments), -1, UPB_NOT_IN_ONEOF, -1, 9, 3}, +}; + +const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_Location_msginit = { + NULL, + &google_protobuf_SourceCodeInfo_Location__fields[0], + NULL, /* TODO. oneofs */ + NULL, /* TODO. default_msg */ + UPB_ALIGNED_SIZEOF(google_protobuf_SourceCodeInfo_Location), 5, 0, false, true +}; + +google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_env *env) { + google_protobuf_SourceCodeInfo_Location *msg = upb_env_malloc(env, sizeof(*msg)); + memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ + return msg; +} +google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_env *env) { + UPB_UNUSED(buf); + UPB_UNUSED(env); + return NULL; +} +char *google_protobuf_SourceCodeInfo_Location_serialize(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env, size_t *size) { + UPB_UNUSED(msg); + UPB_UNUSED(env); + UPB_UNUSED(size); + return NULL; /* TODO. */ +} +upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg) { + return msg->path; +} +void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { + msg->path = value; +} +upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg) { + return msg->span; +} +void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { + msg->span = value; +} +upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { + return msg->leading_comments; +} +void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { + msg->leading_comments = value; +} +upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { + return msg->trailing_comments; +} +void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { + msg->trailing_comments = value; +} +upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg) { + return msg->leading_detached_comments; +} +void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { + msg->leading_detached_comments = value; +} diff --git a/upb/descriptor/descriptor.upb.h b/upb/descriptor/descriptor.upb.h new file mode 100644 index 0000000..41eac35 --- /dev/null +++ b/upb/descriptor/descriptor.upb.h @@ -0,0 +1,527 @@ +/* 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. */ + +#ifndef UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ +#define UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ + +#include "upb/msg.h" + +UPB_BEGIN_EXTERN_C + +struct google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; +struct google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; +struct google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; +struct google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; +struct google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; +struct google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; +struct google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; +struct google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; +struct google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; +struct google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; +struct google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; +struct google_protobuf_FileOptions; +typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; +struct google_protobuf_MessageOptions; +typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; +struct google_protobuf_FieldOptions; +typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; +struct google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; +struct google_protobuf_EnumValueOptions; +typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; +struct google_protobuf_ServiceOptions; +typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; +struct google_protobuf_MethodOptions; +typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; +struct google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; +struct google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; +struct google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; +struct google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; +/* Enums */ + +typedef enum { + google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, + google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, + google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3 +} google_protobuf_FieldDescriptorProto_Label; + +typedef enum { + google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1, + google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2, + google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3, + google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4, + google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5, + google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6, + google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7, + google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8, + google_protobuf_FieldDescriptorProto_TYPE_STRING = 9, + google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10, + google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11, + google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12, + google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13, + google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14, + google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15, + google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16, + google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17, + google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18 +} google_protobuf_FieldDescriptorProto_Type; + +typedef enum { + google_protobuf_FieldOptions_STRING = 0, + google_protobuf_FieldOptions_CORD = 1, + google_protobuf_FieldOptions_STRING_PIECE = 2 +} google_protobuf_FieldOptions_CType; + +typedef enum { + google_protobuf_FieldOptions_JS_NORMAL = 0, + google_protobuf_FieldOptions_JS_STRING = 1, + google_protobuf_FieldOptions_JS_NUMBER = 2 +} google_protobuf_FieldOptions_JSType; + +typedef enum { + google_protobuf_FileOptions_SPEED = 1, + google_protobuf_FileOptions_CODE_SIZE = 2, + google_protobuf_FileOptions_LITE_RUNTIME = 3 +} google_protobuf_FileOptions_OptimizeMode; + +/* google_protobuf_FileDescriptorSet message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorSet_msginit; +google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_env *env); +google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_FileDescriptorSet_serialize(google_protobuf_FileDescriptorSet *msg, upb_env *env, size_t *len); +void google_protobuf_FileDescriptorSet_free(google_protobuf_FileDescriptorSet *msg, upb_env *env); + +/* google_protobuf_FileDescriptorSet getters. */ + +/* google_protobuf_FileDescriptorSet setters. */ + + +/* google_protobuf_FileDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorProto_msginit; +google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_env *env); +google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_FileDescriptorProto_serialize(google_protobuf_FileDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_FileDescriptorProto_free(google_protobuf_FileDescriptorProto *msg, upb_env *env); + +/* google_protobuf_FileDescriptorProto getters. */ +upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg); +upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg); +google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg); +google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg); +upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg); + +/* google_protobuf_FileDescriptorProto setters. */ +void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value); +void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value); +void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value); +void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value); +void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value); + + +/* google_protobuf_DescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_msginit; +google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_env *env); +google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_DescriptorProto_serialize(google_protobuf_DescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_DescriptorProto_free(google_protobuf_DescriptorProto *msg, upb_env *env); + +/* google_protobuf_DescriptorProto getters. */ +upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg); +google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg); + +/* google_protobuf_DescriptorProto setters. */ +void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value); +void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value); + + +/* google_protobuf_DescriptorProto_ExtensionRange message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ExtensionRange_msginit; +google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_env *env); +google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_DescriptorProto_ExtensionRange_serialize(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env, size_t *len); +void google_protobuf_DescriptorProto_ExtensionRange_free(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env); + +/* google_protobuf_DescriptorProto_ExtensionRange getters. */ +int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg); +int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg); + +/* google_protobuf_DescriptorProto_ExtensionRange setters. */ +void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value); +void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value); + + +/* google_protobuf_DescriptorProto_ReservedRange message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ReservedRange_msginit; +google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_env *env); +google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_DescriptorProto_ReservedRange_serialize(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env, size_t *len); +void google_protobuf_DescriptorProto_ReservedRange_free(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env); + +/* google_protobuf_DescriptorProto_ReservedRange getters. */ +int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg); +int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg); + +/* google_protobuf_DescriptorProto_ReservedRange setters. */ +void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value); +void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value); + + +/* google_protobuf_FieldDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_FieldDescriptorProto_msginit; +google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_env *env); +google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_FieldDescriptorProto_serialize(google_protobuf_FieldDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_FieldDescriptorProto_free(google_protobuf_FieldDescriptorProto *msg, upb_env *env); + +/* google_protobuf_FieldDescriptorProto getters. */ +upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg); +upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg); +int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg); +google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg); +google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg); +upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg); +upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg); +google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg); +int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg); +upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg); + +/* google_protobuf_FieldDescriptorProto setters. */ +void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); +void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); +void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value); +void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value); +void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value); +void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); +void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); +void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value); +void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value); +void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); + + +/* google_protobuf_OneofDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_OneofDescriptorProto_msginit; +google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_env *env); +google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_OneofDescriptorProto_serialize(google_protobuf_OneofDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_OneofDescriptorProto_free(google_protobuf_OneofDescriptorProto *msg, upb_env *env); + +/* google_protobuf_OneofDescriptorProto getters. */ +upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg); + +/* google_protobuf_OneofDescriptorProto setters. */ +void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value); + + +/* google_protobuf_EnumDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_msginit; +google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_env *env); +google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_EnumDescriptorProto_serialize(google_protobuf_EnumDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_EnumDescriptorProto_free(google_protobuf_EnumDescriptorProto *msg, upb_env *env); + +/* google_protobuf_EnumDescriptorProto getters. */ +upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg); +google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg); + +/* google_protobuf_EnumDescriptorProto setters. */ +void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value); +void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value); + + +/* google_protobuf_EnumValueDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_EnumValueDescriptorProto_msginit; +google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_env *env); +google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_EnumValueDescriptorProto_serialize(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_EnumValueDescriptorProto_free(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env); + +/* google_protobuf_EnumValueDescriptorProto getters. */ +upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg); +int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg); +google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg); + +/* google_protobuf_EnumValueDescriptorProto setters. */ +void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value); +void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value); +void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value); + + +/* google_protobuf_ServiceDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_ServiceDescriptorProto_msginit; +google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_env *env); +google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_ServiceDescriptorProto_serialize(google_protobuf_ServiceDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_ServiceDescriptorProto_free(google_protobuf_ServiceDescriptorProto *msg, upb_env *env); + +/* google_protobuf_ServiceDescriptorProto getters. */ +upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg); +google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg); + +/* google_protobuf_ServiceDescriptorProto setters. */ +void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value); +void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value); + + +/* google_protobuf_MethodDescriptorProto message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_MethodDescriptorProto_msginit; +google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_env *env); +google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_MethodDescriptorProto_serialize(google_protobuf_MethodDescriptorProto *msg, upb_env *env, size_t *len); +void google_protobuf_MethodDescriptorProto_free(google_protobuf_MethodDescriptorProto *msg, upb_env *env); + +/* google_protobuf_MethodDescriptorProto getters. */ +upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg); +upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg); +upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg); +google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg); +bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg); +bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg); + +/* google_protobuf_MethodDescriptorProto setters. */ +void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value); +void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value); +void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value); +void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value); +void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value); +void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value); + + +/* google_protobuf_FileOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_FileOptions_msginit; +google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_env *env); +google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_FileOptions_serialize(google_protobuf_FileOptions *msg, upb_env *env, size_t *len); +void google_protobuf_FileOptions_free(google_protobuf_FileOptions *msg, upb_env *env); + +/* google_protobuf_FileOptions getters. */ +upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg); +upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg); +google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg); +upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg); +upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg); +upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg); +bool google_protobuf_FileOptions_javanano_use_deprecated_package(const google_protobuf_FileOptions *msg); +upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg); +upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg); + +/* google_protobuf_FileOptions setters. */ +void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value); +void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value); +void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value); +void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value); +void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value); +void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value); +void google_protobuf_FileOptions_set_javanano_use_deprecated_package(google_protobuf_FileOptions *msg, bool value); +void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value); +void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value); + + +/* google_protobuf_MessageOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_MessageOptions_msginit; +google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_env *env); +google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_MessageOptions_serialize(google_protobuf_MessageOptions *msg, upb_env *env, size_t *len); +void google_protobuf_MessageOptions_free(google_protobuf_MessageOptions *msg, upb_env *env); + +/* google_protobuf_MessageOptions getters. */ +bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg); +bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg); +bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg); +bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg); + +/* google_protobuf_MessageOptions setters. */ +void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value); +void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value); +void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value); +void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value); + + +/* google_protobuf_FieldOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_FieldOptions_msginit; +google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_env *env); +google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_FieldOptions_serialize(google_protobuf_FieldOptions *msg, upb_env *env, size_t *len); +void google_protobuf_FieldOptions_free(google_protobuf_FieldOptions *msg, upb_env *env); + +/* google_protobuf_FieldOptions getters. */ +google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg); +bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg); +bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg); +bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg); +google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg); +bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg); + +/* google_protobuf_FieldOptions setters. */ +void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value); +void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value); +void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value); +void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value); +void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value); +void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value); + + +/* google_protobuf_EnumOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_EnumOptions_msginit; +google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_env *env); +google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_EnumOptions_serialize(google_protobuf_EnumOptions *msg, upb_env *env, size_t *len); +void google_protobuf_EnumOptions_free(google_protobuf_EnumOptions *msg, upb_env *env); + +/* google_protobuf_EnumOptions getters. */ +bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg); +bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg); + +/* google_protobuf_EnumOptions setters. */ +void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value); +void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value); + + +/* google_protobuf_EnumValueOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_EnumValueOptions_msginit; +google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_env *env); +google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_EnumValueOptions_serialize(google_protobuf_EnumValueOptions *msg, upb_env *env, size_t *len); +void google_protobuf_EnumValueOptions_free(google_protobuf_EnumValueOptions *msg, upb_env *env); + +/* google_protobuf_EnumValueOptions getters. */ +bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg); + +/* google_protobuf_EnumValueOptions setters. */ +void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value); + + +/* google_protobuf_ServiceOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_ServiceOptions_msginit; +google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_env *env); +google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_ServiceOptions_serialize(google_protobuf_ServiceOptions *msg, upb_env *env, size_t *len); +void google_protobuf_ServiceOptions_free(google_protobuf_ServiceOptions *msg, upb_env *env); + +/* google_protobuf_ServiceOptions getters. */ +bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg); + +/* google_protobuf_ServiceOptions setters. */ +void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value); + + +/* google_protobuf_MethodOptions message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_MethodOptions_msginit; +google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_env *env); +google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_MethodOptions_serialize(google_protobuf_MethodOptions *msg, upb_env *env, size_t *len); +void google_protobuf_MethodOptions_free(google_protobuf_MethodOptions *msg, upb_env *env); + +/* google_protobuf_MethodOptions getters. */ +bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg); + +/* google_protobuf_MethodOptions setters. */ +void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value); + + +/* google_protobuf_UninterpretedOption message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_msginit; +google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_env *env); +google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_UninterpretedOption_serialize(google_protobuf_UninterpretedOption *msg, upb_env *env, size_t *len); +void google_protobuf_UninterpretedOption_free(google_protobuf_UninterpretedOption *msg, upb_env *env); + +/* google_protobuf_UninterpretedOption getters. */ +upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg); +uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg); +int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg); +double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg); +upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg); +upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg); + +/* google_protobuf_UninterpretedOption setters. */ +void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value); +void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value); +void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value); +void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value); +void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value); +void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value); + + +/* google_protobuf_UninterpretedOption_NamePart message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_NamePart_msginit; +google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_env *env); +google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_UninterpretedOption_NamePart_serialize(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env, size_t *len); +void google_protobuf_UninterpretedOption_NamePart_free(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env); + +/* google_protobuf_UninterpretedOption_NamePart getters. */ +upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg); +bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg); + +/* google_protobuf_UninterpretedOption_NamePart setters. */ +void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value); +void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value); + + +/* google_protobuf_SourceCodeInfo message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_msginit; +google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_env *env); +google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_SourceCodeInfo_serialize(google_protobuf_SourceCodeInfo *msg, upb_env *env, size_t *len); +void google_protobuf_SourceCodeInfo_free(google_protobuf_SourceCodeInfo *msg, upb_env *env); + +/* google_protobuf_SourceCodeInfo getters. */ + +/* google_protobuf_SourceCodeInfo setters. */ + + +/* google_protobuf_SourceCodeInfo_Location message definition. */ +extern const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_Location_msginit; +google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_env *env); +google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_env *env); +char *google_protobuf_SourceCodeInfo_Location_serialize(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env, size_t *len); +void google_protobuf_SourceCodeInfo_Location_free(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env); + +/* google_protobuf_SourceCodeInfo_Location getters. */ +upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg); +upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg); + +/* google_protobuf_SourceCodeInfo_Location setters. */ +void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value); +void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value); + + +UPB_END_EXTERN_C + +#endif /* UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ */ diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c index 624c3ae..da89622 100644 --- a/upb/descriptor/reader.c +++ b/upb/descriptor/reader.c @@ -48,6 +48,7 @@ typedef struct { struct upb_descreader { upb_sink sink; upb_inttable files; + upb_strtable files_by_name; upb_filedef *file; /* The last file in files. */ upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; int stack_len; @@ -214,6 +215,7 @@ static size_t file_onname(void *closure, const void *hd, const char *buf, UPB_UNUSED(handle); name = upb_gstrndup(buf, n); + upb_strtable_insert(&r->files_by_name, name, upb_value_ptr(r->file)); /* XXX: see comment at the top of the file. */ ok = upb_filedef_setname(r->file, name, NULL); upb_gfree(name); @@ -327,6 +329,18 @@ static void *file_startext(void *closure, const void *hd) { return r; } +static size_t file_ondep(void *closure, const void *hd, const char *buf, + size_t n, const upb_bufhandle *handle) { + upb_descreader *r = closure; + upb_value val; + if (upb_strtable_lookup2(&r->files_by_name, buf, n, &val)) { + upb_filedef_adddep(r->file, upb_value_getptr(val)); + } + UPB_UNUSED(hd); + UPB_UNUSED(handle); + return n; +} + /** Handlers for google.protobuf.EnumValueDescriptorProto. *********************/ static bool enumval_startmsg(void *closure, const void *hd) { @@ -771,6 +785,8 @@ static void reghandlers(const void *closure, upb_handlers *h) { &file_startenum, NULL); upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension), &file_startext, NULL); + upb_handlers_setstring(h, F(FileDescriptorProto, dependency), + &file_ondep, NULL); } else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) { upb_handlers_setstartmsg(h, &enumval_startmsg, NULL); upb_handlers_setendmsg(h, &enumval_endmsg, NULL); @@ -830,6 +846,7 @@ void descreader_cleanup(void *_r) { upb_gfree(r->name); upb_inttable_uninit(&r->files); + upb_strtable_uninit(&r->files_by_name); upb_inttable_uninit(&r->oneofs); upb_gfree(r->default_string); while (r->stack_len > 0) { @@ -848,6 +865,7 @@ upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) { } upb_inttable_init(&r->files, UPB_CTYPE_PTR); + upb_strtable_init(&r->files_by_name, UPB_CTYPE_PTR); upb_inttable_init(&r->oneofs, UPB_CTYPE_PTR); upb_sink_reset(upb_descreader_input(r), h, r); r->stack_len = 0; diff --git a/upb/encode.c b/upb/encode.c new file mode 100644 index 0000000..2fe1cc3 --- /dev/null +++ b/upb/encode.c @@ -0,0 +1,381 @@ + +#include "upb/encode.h" +#include "upb/structs.int.h" + +#define UPB_PB_VARINT_MAX_LEN 10 +#define CHK(x) do { if (!(x)) { return false; } } while(0) + +static size_t upb_encode_varint(uint64_t val, char *buf) { + size_t i; + if (val == 0) { buf[0] = 0; return 1; } + i = 0; + while (val) { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } + return i; +} + +static uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); } +static uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); } + +typedef enum { + UPB_WIRE_TYPE_VARINT = 0, + UPB_WIRE_TYPE_64BIT = 1, + UPB_WIRE_TYPE_DELIMITED = 2, + UPB_WIRE_TYPE_START_GROUP = 3, + UPB_WIRE_TYPE_END_GROUP = 4, + UPB_WIRE_TYPE_32BIT = 5 +} upb_wiretype_t; + +/* Index is descriptor type. */ +const uint8_t upb_native_wiretypes[] = { + UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */ + UPB_WIRE_TYPE_64BIT, /* DOUBLE */ + UPB_WIRE_TYPE_32BIT, /* FLOAT */ + UPB_WIRE_TYPE_VARINT, /* INT64 */ + UPB_WIRE_TYPE_VARINT, /* UINT64 */ + UPB_WIRE_TYPE_VARINT, /* INT32 */ + UPB_WIRE_TYPE_64BIT, /* FIXED64 */ + UPB_WIRE_TYPE_32BIT, /* FIXED32 */ + UPB_WIRE_TYPE_VARINT, /* BOOL */ + UPB_WIRE_TYPE_DELIMITED, /* STRING */ + UPB_WIRE_TYPE_START_GROUP, /* GROUP */ + UPB_WIRE_TYPE_DELIMITED, /* MESSAGE */ + UPB_WIRE_TYPE_DELIMITED, /* BYTES */ + UPB_WIRE_TYPE_VARINT, /* UINT32 */ + UPB_WIRE_TYPE_VARINT, /* ENUM */ + UPB_WIRE_TYPE_32BIT, /* SFIXED32 */ + UPB_WIRE_TYPE_64BIT, /* SFIXED64 */ + UPB_WIRE_TYPE_VARINT, /* SINT32 */ + UPB_WIRE_TYPE_VARINT, /* SINT64 */ +}; + +typedef struct { + upb_env *env; + char *buf, *ptr, *limit; +} upb_encstate; + +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; +} + +static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size); + CHK(new_buf); + + /* We want previous data at the end, realloc() put it at the beginning. */ + memmove(e->limit - old_size, e->buf, old_size); + + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + return true; +} + +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ +static bool upb_encode_reserve(upb_encstate *e, size_t bytes) { + CHK(UPB_LIKELY((size_t)(e->ptr - e->buf) >= bytes) || + upb_encode_growbuffer(e, bytes)); + + e->ptr -= bytes; + return true; +} + +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static bool upb_put_bytes(upb_encstate *e, const void *data, size_t len) { + CHK(upb_encode_reserve(e, len)); + memcpy(e->ptr, data, len); + return true; +} + +static bool upb_put_fixed64(upb_encstate *e, uint64_t val) { + /* TODO(haberman): byte-swap for big endian. */ + return upb_put_bytes(e, &val, sizeof(uint64_t)); +} + +static bool upb_put_fixed32(upb_encstate *e, uint32_t val) { + /* TODO(haberman): byte-swap for big endian. */ + return upb_put_bytes(e, &val, sizeof(uint32_t)); +} + +static bool upb_put_varint(upb_encstate *e, uint64_t val) { + size_t len; + char *start; + CHK(upb_encode_reserve(e, UPB_PB_VARINT_MAX_LEN)); + len = upb_encode_varint(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; + return true; +} + +static bool upb_put_double(upb_encstate *e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + return upb_put_fixed64(e, u64); +} + +static bool upb_put_float(upb_encstate *e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + return upb_put_fixed32(e, u32); +} + +static uint32_t upb_readcase(const char *msg, const upb_msglayout_msginit_v1 *m, + int oneof_index) { + uint32_t ret; + memcpy(&ret, msg + m->oneofs[oneof_index].case_offset, sizeof(ret)); + return ret; +} + +static bool upb_readhasbit(const char *msg, + const upb_msglayout_fieldinit_v1 *f) { + UPB_ASSERT(f->hasbit != UPB_NO_HASBIT); + return msg[f->hasbit / 8] & (1 << (f->hasbit % 8)); +} + +static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) { + return upb_put_varint(e, (field_number << 3) | wire_type); +} + +static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr, + size_t size) { + size_t bytes = arr->len * size; + return upb_put_bytes(e, arr->data, bytes) && upb_put_varint(e, bytes); +} + +bool upb_encode_message(upb_encstate *e, const char *msg, + const upb_msglayout_msginit_v1 *m, + size_t *size); + +static bool upb_encode_array(upb_encstate *e, const char *field_mem, + const upb_msglayout_msginit_v1 *m, + const upb_msglayout_fieldinit_v1 *f) { + const upb_array *arr = *(const upb_array**)field_mem; + + if (arr->len == 0) { + return true; + } + +#define VARINT_CASE(ctype, encode) do { \ + uint64_t *start = arr->data; \ + uint64_t *ptr = start + arr->len; \ + char *buf_ptr = e->ptr; \ + do { \ + ptr--; \ + CHK(upb_put_varint(e, encode)); \ + } while (ptr != start); \ + CHK(upb_put_varint(e, buf_ptr - e->ptr)); \ + break; \ +} while(0) + + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_DOUBLE: + CHK(upb_put_fixedarray(e, arr, sizeof(double))); + break; + case UPB_DESCRIPTOR_TYPE_FLOAT: + CHK(upb_put_fixedarray(e, arr, sizeof(float))); + break; + case UPB_DESCRIPTOR_TYPE_SFIXED64: + case UPB_DESCRIPTOR_TYPE_FIXED64: + CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t))); + break; + case UPB_DESCRIPTOR_TYPE_FIXED32: + case UPB_DESCRIPTOR_TYPE_SFIXED32: + CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t))); + break; + case UPB_DESCRIPTOR_TYPE_INT64: + case UPB_DESCRIPTOR_TYPE_UINT64: + VARINT_CASE(uint64_t, *ptr); + case UPB_DESCRIPTOR_TYPE_UINT32: + case UPB_DESCRIPTOR_TYPE_INT32: + case UPB_DESCRIPTOR_TYPE_ENUM: + VARINT_CASE(uint32_t, *ptr); + case UPB_DESCRIPTOR_TYPE_BOOL: + VARINT_CASE(bool, *ptr); + case UPB_DESCRIPTOR_TYPE_SINT32: + VARINT_CASE(int32_t, upb_zzenc_32(*ptr)); + case UPB_DESCRIPTOR_TYPE_SINT64: + VARINT_CASE(int64_t, upb_zzenc_64(*ptr)); + case UPB_DESCRIPTOR_TYPE_STRING: + case UPB_DESCRIPTOR_TYPE_BYTES: { + upb_stringview *start = arr->data; + upb_stringview *ptr = start + arr->len; + do { + ptr--; + CHK(upb_put_bytes(e, ptr->data, ptr->size) && + upb_put_varint(e, ptr->size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + } while (ptr != start); + return true; + } + case UPB_DESCRIPTOR_TYPE_GROUP: { + void **start = arr->data; + void **ptr = start + arr->len; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + do { + size_t size; + ptr--; + CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && + upb_encode_message(e, *ptr, subm, &size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP)); + } while (ptr != start); + return true; + } + case UPB_DESCRIPTOR_TYPE_MESSAGE: { + void **start = arr->data; + void **ptr = start + arr->len; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + do { + size_t size; + ptr--; + CHK(upb_encode_message(e, *ptr, subm, &size) && + upb_put_varint(e, size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + } while (ptr != start); + return true; + } + } +#undef VARINT_CASE + + /* We encode all primitive arrays as packed, regardless of what was specified + * in the .proto file. Could special case 1-sized arrays. */ + CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED)); + return true; +} + +static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, + const upb_msglayout_msginit_v1 *m, + const upb_msglayout_fieldinit_v1 *f, + bool is_proto3) { +#define CASE(ctype, type, wire_type, encodeval) do { \ + ctype val = *(ctype*)field_mem; \ + if (is_proto3 && val == 0) { \ + return true; \ + } \ + return upb_put_ ## type(e, encodeval) && \ + upb_put_tag(e, f->number, wire_type); \ +} while(0) + + switch (f->type) { + case UPB_DESCRIPTOR_TYPE_DOUBLE: + CASE(double, double, UPB_WIRE_TYPE_64BIT, val); + case UPB_DESCRIPTOR_TYPE_FLOAT: + CASE(float, float, UPB_WIRE_TYPE_32BIT, val); + case UPB_DESCRIPTOR_TYPE_INT64: + case UPB_DESCRIPTOR_TYPE_UINT64: + CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val); + case UPB_DESCRIPTOR_TYPE_UINT32: + case UPB_DESCRIPTOR_TYPE_INT32: + case UPB_DESCRIPTOR_TYPE_ENUM: + CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); + case UPB_DESCRIPTOR_TYPE_SFIXED64: + case UPB_DESCRIPTOR_TYPE_FIXED64: + CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val); + case UPB_DESCRIPTOR_TYPE_FIXED32: + case UPB_DESCRIPTOR_TYPE_SFIXED32: + CASE(uint32_t, fixed32, UPB_WIRE_TYPE_32BIT, val); + case UPB_DESCRIPTOR_TYPE_BOOL: + CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val); + case UPB_DESCRIPTOR_TYPE_SINT32: + CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzenc_32(val)); + case UPB_DESCRIPTOR_TYPE_SINT64: + CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzenc_64(val)); + case UPB_DESCRIPTOR_TYPE_STRING: + case UPB_DESCRIPTOR_TYPE_BYTES: { + upb_stringview view = *(upb_stringview*)field_mem; + if (is_proto3 && view.size == 0) { + return true; + } + return upb_put_bytes(e, view.data, view.size) && + upb_put_varint(e, view.size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + } + case UPB_DESCRIPTOR_TYPE_GROUP: { + size_t size; + void *submsg = *(void**)field_mem; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + if (is_proto3 && submsg == NULL) { + return true; + } + return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && + upb_encode_message(e, submsg, subm, &size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP); + } + case UPB_DESCRIPTOR_TYPE_MESSAGE: { + size_t size; + void *submsg = *(void**)field_mem; + const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + if (is_proto3 && submsg == NULL) { + return true; + } + return upb_encode_message(e, submsg, subm, &size) && + upb_put_varint(e, size) && + upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + } + } +#undef CASE + UPB_UNREACHABLE(); +} + +bool upb_encode_hasscalarfield(const char *msg, + const upb_msglayout_msginit_v1 *m, + const upb_msglayout_fieldinit_v1 *f) { + if (f->oneof_index != UPB_NOT_IN_ONEOF) { + return upb_readcase(msg, m, f->oneof_index) == f->number; + } else if (m->is_proto2) { + return upb_readhasbit(msg, f); + } else { + /* For proto3, we'll test for the field being empty later. */ + return true; + } +} + +bool upb_encode_message(upb_encstate* e, const char *msg, + const upb_msglayout_msginit_v1 *m, + size_t *size) { + int i; + char *buf_end = e->ptr; + for (i = m->field_count - 1; i >= 0; i--) { + const upb_msglayout_fieldinit_v1 *f = &m->fields[i]; + + if (f->label == UPB_LABEL_REPEATED) { + CHK(upb_encode_array(e, msg, m, f)); + } else { + if (upb_encode_hasscalarfield(msg, m, f)) { + CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2)); + } + } + } + + *size = buf_end - e->ptr; + return true; +} + +char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *m, + upb_env *env, size_t *size) { + upb_encstate e; + e.env = env; + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + + if (!upb_encode_message(&e, msg, m, size)) { + return false; + } + + *size = e.limit - e.ptr; + return e.ptr; +} diff --git a/upb/encode.h b/upb/encode.h new file mode 100644 index 0000000..83908d4 --- /dev/null +++ b/upb/encode.h @@ -0,0 +1,17 @@ +/* +** upb_encode: parsing into a upb_msg using a upb_msglayout. +*/ + +#ifndef UPB_ENCODE_H_ +#define UPB_ENCODE_H_ + +#include "upb/msg.h" + +UPB_BEGIN_EXTERN_C + +char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *l, + upb_env *env, size_t *size); + +UPB_END_EXTERN_C + +#endif /* UPB_ENCODE_H_ */ @@ -1,5 +1,6 @@ #include "upb/msg.h" +#include "upb/structs.int.h" static bool is_power_of_two(size_t val) { return (val & (val - 1)) == 0; @@ -170,7 +171,6 @@ static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { size_t ret; l->data.size = align_up(l->data.size, size); - l->data.align = align_up(l->data.align, size); ret = l->data.size; l->data.size += size; return ret; @@ -231,7 +231,7 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { upb_msglayout_fieldinit_v1 *fields; upb_msglayout_oneofinit_v1 *oneofs; - for (upb_msg_field_begin(&it, m), hasbit = sizeof(void*) * 8; + for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); upb_msg_field_next(&it)) { const upb_fielddef* f = upb_msg_iter_field(&it); @@ -300,7 +300,6 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { /* Account for space used by hasbits. */ l->data.size = div_round_up(hasbit, 8); - l->data.align = 1; /* Allocate non-oneof fields. */ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); @@ -343,7 +342,7 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { /* Size of the entire structure should be a multiple of its greatest * alignment. */ - l->data.size = align_up(l->data.size, l->data.align); + l->data.size = align_up(l->data.size, 8 /* TODO: track for real? */); if (upb_msglayout_initdefault(l, m)) { return l; @@ -796,15 +795,6 @@ void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, /** upb_array *****************************************************************/ -struct upb_array { - upb_fieldtype_t type; - uint8_t element_size; - void *data; /* Each element is element_size. */ - size_t len; /* Measured in elements. */ - size_t size; /* Measured in elements. */ - upb_alloc *alloc; -}; - #define DEREF_ARR(arr, i, type) ((type*)arr->data)[i] size_t upb_array_sizeof(upb_fieldtype_t type) { @@ -387,11 +387,7 @@ bool upb_msg_getscalarhandlerdata(const upb_handlers *h, /** Interfaces for generated code *********************************************/ #define UPB_NOT_IN_ONEOF UINT16_MAX - -typedef struct { - const char *ptr; - uint32_t length; -} upb_msglayout_strinit_v1; +#define UPB_NO_HASBIT UINT16_MAX typedef struct { uint32_t number; @@ -409,21 +405,22 @@ typedef struct { } upb_msglayout_oneofinit_v1; typedef struct upb_msglayout_msginit_v1 { - const struct upb_msglayout_msginit_v1 **submsgs; + const struct upb_msglayout_msginit_v1 *const* submsgs; const upb_msglayout_fieldinit_v1 *fields; const upb_msglayout_oneofinit_v1 *oneofs; - uint32_t *case_offsets; void *default_msg; - /* Must be aligned to 8. Doesn't include internal members like unknown - * fields, extension dict, pointer to msglayout, etc. */ + /* Must be aligned to sizeof(void*). Doesn't include internal members like + * unknown * fields, extension dict, pointer to msglayout, etc. */ uint32_t size; uint16_t field_count; uint16_t oneof_count; bool extendable; bool is_proto2; - char align; } upb_msglayout_msginit_v1; +#define UPB_ALIGN_UP_TO(val, align) ((val + (align - 1)) & -align) +#define UPB_ALIGNED_SIZEOF(type) UPB_ALIGN_UP_TO(sizeof(type), sizeof(void*)) + /* Initialize/uninitialize a msglayout from a msginit. If upb uses v1 * internally, this will not allocate any memory. Should only be used by * generated code. */ diff --git a/upb/structs.int.h b/upb/structs.int.h new file mode 100644 index 0000000..242155b --- /dev/null +++ b/upb/structs.int.h @@ -0,0 +1,18 @@ +/* +** structs.int.h: structures definitions that are internal to upb. +*/ + +#ifndef UPB_STRUCTS_H_ +#define UPB_STRUCTS_H_ + +struct upb_array { + upb_fieldtype_t type; + uint8_t element_size; + void *data; /* Each element is element_size. */ + size_t len; /* Measured in elements. */ + size_t size; /* Measured in elements. */ + upb_alloc *alloc; +}; + +#endif /* UPB_STRUCTS_H_ */ + @@ -34,6 +34,9 @@ template <int N> class InlinedEnvironment; #define UPB_INLINE static #endif +/* Hints to the compiler about likely/unlikely branches. */ +#define UPB_LIKELY(x) __builtin_expect((x),1) + /* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler * doesn't provide these preprocessor symbols. */ #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) |