Merge branch 'master' into size-benchmarks
diff --git a/.bazelrc b/.bazelrc
index df04df1..7b9da71 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -18,3 +18,5 @@
build:analyzer --per_file_copt=json/parser@-fno-analyzer
build:analyzer --per_file_copt=com_google_protobuf@-fno-analyzer
build:analyzer --per_file_copt=com_github_google_benchmark@-fno-analyzer
+
+build:asan-fuzzer --copt=-fsanitize=address,fuzzer --linkopt=-fsanitize=address,fuzzer --define fuzz=true
diff --git a/BUILD b/BUILD
index 6893310..5ba41c9 100644
--- a/BUILD
+++ b/BUILD
@@ -5,6 +5,7 @@
)
load(
"//bazel:upb_proto_library.bzl",
+ "upb_fasttable_enabled",
"upb_proto_library",
"upb_proto_library_copts",
"upb_proto_reflection_library",
@@ -26,14 +27,19 @@
])
config_setting(
- name = "darwin",
- values = {"cpu": "darwin"},
+ name = "windows",
+ constraint_values = ["@bazel_tools//platforms:windows"],
+)
+
+upb_fasttable_enabled(
+ name = "fasttable_enabled",
+ build_setting_default = False,
visibility = ["//visibility:public"],
)
config_setting(
- name = "windows",
- constraint_values = ["@bazel_tools//platforms:windows"],
+ name = "fasttable_enabled_setting",
+ flag_values = {"//:fasttable_enabled": "true"},
)
upb_proto_library_copts(
@@ -58,6 +64,7 @@
name = "upb",
srcs = [
"upb/decode.c",
+ "upb/decode.int.h",
"upb/encode.c",
"upb/msg.c",
"upb/msg.h",
@@ -65,7 +72,6 @@
"upb/table.int.h",
"upb/upb.c",
"upb/upb.int.h",
- "third_party/wyhash/wyhash.h",
],
hdrs = [
"upb/decode.h",
@@ -75,7 +81,27 @@
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
- deps = [":port"],
+ deps = [
+ ":fastdecode",
+ ":port",
+ "//third_party/wyhash",
+ ],
+)
+
+cc_library(
+ name = "fastdecode",
+ srcs = [
+ "upb/decode.int.h",
+ "upb/decode_fast.c",
+ "upb/decode_fast.h",
+ "upb/msg.h",
+ "upb/upb.int.h",
+ ],
+ copts = UPB_DEFAULT_COPTS,
+ deps = [
+ ":port",
+ ":table",
+ ],
)
# Common support routines used by generated code. This library has no
@@ -87,6 +113,7 @@
cc_library(
name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
hdrs = [
+ "upb/decode_fast.h",
"upb/msg.h",
"upb/port_def.inc",
"upb/port_undef.inc",
@@ -172,11 +199,13 @@
cc_library(
name = "table",
- hdrs = ["upb/table.int.h"],
+ hdrs = [
+ "upb/table.int.h",
+ "upb/upb.h",
+ ],
visibility = ["//tests:__pkg__"],
deps = [
":port",
- ":upb",
],
)
@@ -275,6 +304,7 @@
amalgamator = ":amalgamate",
libs = [
":upb",
+ ":fastdecode",
":descriptor_upb_proto",
":reflection",
":handlers",
@@ -286,12 +316,10 @@
cc_library(
name = "amalgamation",
- srcs = [
- "upb.c",
- "third_party/wyhash/wyhash.h",
- ],
+ srcs = ["upb.c"],
hdrs = ["upb.h"],
copts = UPB_DEFAULT_COPTS,
+ deps = ["//third_party/wyhash"],
)
upb_amalgamation(
@@ -303,6 +331,7 @@
amalgamator = ":amalgamate",
libs = [
":upb",
+ ":fastdecode",
":descriptor_upb_proto",
":descriptor_upb_proto_reflection",
":reflection",
@@ -314,13 +343,10 @@
cc_library(
name = "php_amalgamation",
- srcs = [
- "php-upb.c",
- "third_party/wyhash/wyhash.h",
- ],
+ srcs = ["php-upb.c"],
hdrs = ["php-upb.h"],
copts = UPB_DEFAULT_COPTS,
-
+ deps = ["//third_party/wyhash"],
)
upb_amalgamation(
@@ -332,6 +358,7 @@
amalgamator = ":amalgamate",
libs = [
":upb",
+ ":fastdecode",
":descriptor_upb_proto",
":reflection",
":port",
@@ -342,12 +369,10 @@
cc_library(
name = "ruby_amalgamation",
- srcs = [
- "ruby-upb.c",
- "third_party/wyhash/wyhash.h",
- ],
+ srcs = ["ruby-upb.c"],
hdrs = ["ruby-upb.h"],
copts = UPB_DEFAULT_COPTS,
+ deps = ["//third_party/wyhash"],
)
exports_files(
diff --git a/bazel/build_defs.bzl b/bazel/build_defs.bzl
index 4413d94..ae41577 100644
--- a/bazel/build_defs.bzl
+++ b/bazel/build_defs.bzl
@@ -16,6 +16,7 @@
UPB_DEFAULT_COPTS = select({
"//:windows": [],
+ "//:fasttable_enabled_setting": ["-std=gnu99", "-DUPB_ENABLE_FASTTABLE"],
"//conditions:default": [
# copybara:strip_for_google3_begin
"-std=c99",
diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl
index 8a1b285..d4d5160 100644
--- a/bazel/upb_proto_library.bzl
+++ b/bazel/upb_proto_library.bzl
@@ -107,6 +107,28 @@
linking_context = linking_context,
)
+# Build setting for whether fasttable code generation is enabled ###############
+
+_FastTableEnabled = provider(
+ fields = {
+ "enabled": "whether fasttable is enabled",
+ },
+)
+
+def fasttable_enabled_impl(ctx):
+ raw_setting = ctx.build_setting_value
+
+ if raw_setting:
+ # TODO(haberman): check that the target CPU supports fasttable.
+ pass
+
+ return _FastTableEnabled(enabled = raw_setting)
+
+upb_fasttable_enabled = rule(
+ implementation = fasttable_enabled_impl,
+ build_setting = config.bool(flag = True),
+)
+
# Dummy rule to expose select() copts to aspects ##############################
_UpbProtoLibraryCopts = provider(
@@ -144,6 +166,8 @@
srcs = [_generate_output_file(ctx, name, ext + ".c") for name in proto_sources]
hdrs = [_generate_output_file(ctx, name, ext + ".h") for name in proto_sources]
transitive_sets = proto_info.transitive_descriptor_sets.to_list()
+ fasttable_enabled = ctx.attr._fasttable_enabled[_FastTableEnabled].enabled
+ codegen_params = "fasttable:" if fasttable_enabled else ""
ctx.actions.run(
inputs = depset(
direct = [proto_info.direct_descriptor_set],
@@ -153,7 +177,7 @@
outputs = srcs + hdrs,
executable = ctx.executable._protoc,
arguments = [
- "--upb_out=" + _get_real_root(srcs[0]),
+ "--upb_out=" + codegen_params + _get_real_root(srcs[0]),
"--plugin=protoc-gen-upb=" + ctx.executable._upbc.path,
"--descriptor_set_in=" + ctx.configuration.host_path_separator.join([f.path for f in transitive_sets]),
] +
@@ -258,6 +282,7 @@
"//:upb",
]),
"_ext": attr.string(default = ".upb"),
+ "_fasttable_enabled": attr.label(default = "//:fasttable_enabled"),
}),
implementation = _upb_proto_library_aspect_impl,
provides = [
@@ -267,6 +292,7 @@
attr_aspects = ["deps"],
fragments = ["cpp"],
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
+ incompatible_use_toolchain_transition = True,
)
upb_proto_library = rule(
@@ -316,6 +342,7 @@
],
),
"_ext": attr.string(default = ".upbdefs"),
+ "_fasttable_enabled": attr.label(default = "//:fasttable_enabled"),
}),
implementation = _upb_proto_reflection_library_aspect_impl,
provides = [
@@ -329,6 +356,7 @@
attr_aspects = ["deps"],
fragments = ["cpp"],
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
+ incompatible_use_toolchain_transition = True,
)
upb_proto_reflection_library = rule(
diff --git a/benchmarks/BUILD b/benchmarks/BUILD
index b0e598c..a937acc 100644
--- a/benchmarks/BUILD
+++ b/benchmarks/BUILD
@@ -51,14 +51,15 @@
testonly = 1,
srcs = ["benchmark.cc"],
deps = [
+ ":ads_upb_proto_reflection",
":benchmark_descriptor_cc_proto",
":benchmark_descriptor_sv_cc_proto",
":benchmark_descriptor_upb_proto",
":benchmark_descriptor_upb_proto_reflection",
- ":ads_upb_proto_reflection",
"//:descriptor_upb_proto",
"//:reflection",
"@com_github_google_benchmark//:benchmark_main",
+ "@com_google_absl//absl/container:flat_hash_set",
"@com_google_protobuf//:protobuf",
],
)
diff --git a/benchmarks/BUILD.googleapis b/benchmarks/BUILD.googleapis
index c90815b..904bdec 100644
--- a/benchmarks/BUILD.googleapis
+++ b/benchmarks/BUILD.googleapis
@@ -15,15 +15,15 @@
#srcs = ["google/ads/googleads/v5/services/google_ads_service.proto"],
visibility = ["//visibility:public"],
deps = [
- "@com_google_protobuf//:any_proto",
- "@com_google_protobuf//:empty_proto",
- "@com_google_protobuf//:descriptor_proto",
- "@com_google_protobuf//:field_mask_proto",
- "@com_google_protobuf//:duration_proto",
- "@com_google_protobuf//:timestamp_proto",
- "@com_google_protobuf//:struct_proto",
- "@com_google_protobuf//:api_proto",
- "@com_google_protobuf//:type_proto",
- "@com_google_protobuf//:wrappers_proto",
+ "@com_google_protobuf//:any_proto",
+ "@com_google_protobuf//:api_proto",
+ "@com_google_protobuf//:descriptor_proto",
+ "@com_google_protobuf//:duration_proto",
+ "@com_google_protobuf//:empty_proto",
+ "@com_google_protobuf//:field_mask_proto",
+ "@com_google_protobuf//:struct_proto",
+ "@com_google_protobuf//:timestamp_proto",
+ "@com_google_protobuf//:type_proto",
+ "@com_google_protobuf//:wrappers_proto",
],
)
diff --git a/benchmarks/benchmark.cc b/benchmarks/benchmark.cc
index 7bb7f12..cc510bd 100644
--- a/benchmarks/benchmark.cc
+++ b/benchmarks/benchmark.cc
@@ -2,17 +2,13 @@
#include <benchmark/benchmark.h>
#include <string.h>
-// For benchmarks of parsing speed.
+#include "absl/container/flat_hash_set.h"
#include "benchmarks/descriptor.pb.h"
#include "benchmarks/descriptor.upb.h"
#include "benchmarks/descriptor.upbdefs.h"
#include "benchmarks/descriptor_sv.pb.h"
-
-// For for benchmarks of building descriptors.
#include "google/ads/googleads/v5/services/google_ads_service.upbdefs.h"
#include "google/protobuf/descriptor.pb.h"
-#include "google/protobuf/descriptor.upb.h"
-#include "google/protobuf/descriptor.upbdefs.h"
#include "upb/def.hpp"
upb_strview descriptor = benchmarks_descriptor_proto_upbdefinit.descriptor;
@@ -23,7 +19,7 @@
void CollectFileDescriptors(const upb_def_init* file,
std::vector<upb_strview>& serialized_files,
- std::unordered_set<const upb_def_init*>& seen) {
+ absl::flat_hash_set<const upb_def_init*>& seen) {
if (!seen.insert(file).second) return;
for (upb_def_init **deps = file->deps; *deps; deps++) {
CollectFileDescriptors(*deps, serialized_files, seen);
@@ -53,7 +49,7 @@
size_t bytes_per_iter = 0;
for (auto _ : state) {
upb::SymbolTable symtab;
- google_protobuf_DescriptorProto_getmsgdef(symtab.ptr());
+ upb_benchmark_DescriptorProto_getmsgdef(symtab.ptr());
bytes_per_iter = _upb_symtab_bytesloaded(symtab.ptr());
}
state.SetBytesProcessed(state.iterations() * bytes_per_iter);
@@ -93,7 +89,7 @@
static void BM_LoadAdsDescriptor_Proto2(benchmark::State& state) {
extern upb_def_init google_ads_googleads_v5_services_google_ads_service_proto_upbdefinit;
std::vector<upb_strview> serialized_files;
- std::unordered_set<const upb_def_init*> seen_files;
+ absl::flat_hash_set<const upb_def_init*> seen_files;
CollectFileDescriptors(
&google_ads_googleads_v5_services_google_ads_service_proto_upbdefinit,
serialized_files, seen_files);
@@ -195,7 +191,7 @@
const protobuf::MessageLite::ParseFlags kMergePartial =
protobuf::MessageLite::ParseFlags::kMergePartial;
-const protobuf::MessageLite::ParseFlags kAliasStrings =
+const protobuf::MessageLite::ParseFlags kAlias =
protobuf::MessageLite::ParseFlags::kMergePartialWithAliasing;
template <class P, template <class> class Factory,
@@ -221,9 +217,9 @@
//BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, NoArena);
//BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, WithArena);
BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, WithInitialBlock);
-//BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, NoArena, kAliasStrings);
-//BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, WithArena, kAliasStrings);
-BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, WithInitialBlock, kAliasStrings);
+//BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, NoArena, kAlias);
+//BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, WithArena, kAlias);
+BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, WithInitialBlock, kAlias);
static void BM_SerializeDescriptor_Proto2(benchmark::State& state) {
size_t bytes = 0;
diff --git a/benchmarks/compare.py b/benchmarks/compare.py
index ad8a190..9824ca0 100755
--- a/benchmarks/compare.py
+++ b/benchmarks/compare.py
@@ -27,13 +27,16 @@
def Run(cmd):
subprocess.check_call(cmd, shell=True)
-def Benchmark(outbase, bench_cpu=True, runs=12):
+def Benchmark(outbase, bench_cpu=True, runs=12, new=False):
tmpfile = "/tmp/bench-output.json"
Run("rm -rf {}".format(tmpfile))
Run("CC=clang bazel test ...")
if bench_cpu:
- Run("CC=clang bazel build -c opt --copt=-march=native benchmarks:benchmark")
+ if new:
+ Run("CC=clang bazel build -c opt --copt=-march=native --//:fasttable_enabled=true benchmarks:benchmark")
+ else:
+ Run("CC=clang bazel build -c opt --copt=-march=native benchmarks:benchmark")
Run("./bazel-bin/benchmarks/benchmark --benchmark_out_format=json --benchmark_out={} --benchmark_repetitions={}".format(tmpfile, runs))
with open(tmpfile) as f:
@@ -48,7 +51,10 @@
values = (name, run["iterations"], run["cpu_time"])
print("{} {} {} ns/op".format(*values), file=f)
- Run("CC=clang bazel build -c opt --copt=-g tests:conformance_upb")
+ if new:
+ Run("CC=clang bazel build -c opt --copt=-g --//:fasttable_enabled=true tests:conformance_upb")
+ else:
+ Run("CC=clang bazel build -c opt --copt=-g tests:conformance_upb")
Run("cp -f bazel-bin/tests/conformance_upb {}.bin".format(outbase))
@@ -63,7 +69,7 @@
pass
# Benchmark our current directory first, since it's more likely to be broken.
-Benchmark("/tmp/new", bench_cpu)
+Benchmark("/tmp/new", bench_cpu, new=True)
# Benchmark the baseline.
with GitWorktree(baseline):
diff --git a/cmake/BUILD b/cmake/BUILD
index d59475d..53fbd07 100644
--- a/cmake/BUILD
+++ b/cmake/BUILD
@@ -28,6 +28,7 @@
"//:BUILD",
"//:WORKSPACE",
"//:cmake_files",
+ "//third_party/wyhash:cmake_files",
":cmake_files",
],
outs = ["generated-in/CMakeLists.txt"],
@@ -84,6 +85,7 @@
data = [
":cmake_files",
"//:cmake_files",
+ "//third_party/wyhash:cmake_files",
],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 638482d..d4cbcc9 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -64,6 +64,7 @@
add_library(port INTERFACE)
add_library(upb
../upb/decode.c
+ ../upb/decode.int.h
../upb/encode.c
../upb/msg.c
../upb/msg.h
@@ -71,13 +72,23 @@
../upb/table.int.h
../upb/upb.c
../upb/upb.int.h
- ../third_party/wyhash/wyhash.h
../upb/decode.h
../upb/encode.h
../upb/upb.h
../upb/upb.hpp)
target_link_libraries(upb
- port)
+ fastdecode
+ port
+ /third_party/wyhash)
+add_library(fastdecode
+ ../upb/decode.int.h
+ ../upb/decode_fast.c
+ ../upb/decode_fast.h
+ ../upb/msg.h
+ ../upb/upb.int.h)
+target_link_libraries(fastdecode
+ port
+ table)
add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
table
@@ -111,8 +122,7 @@
upb)
add_library(table INTERFACE)
target_link_libraries(table INTERFACE
- port
- upb)
+ port)
add_library(handlers
../upb/handlers.c
../upb/handlers-inl.h
@@ -150,5 +160,6 @@
target_link_libraries(upb_json
upb
upb_pb)
+add_library(wyhash INTERFACE)
diff --git a/cmake/build_defs.bzl b/cmake/build_defs.bzl
index 83f2f7a..34b4537 100644
--- a/cmake/build_defs.bzl
+++ b/cmake/build_defs.bzl
@@ -1,4 +1,3 @@
-
def generated_file_staleness_test(name, outs, generated_pattern):
"""Tests that checked-in file(s) match the contents of generated file(s).
diff --git a/cmake/google/protobuf/descriptor.upb.c b/cmake/google/protobuf/descriptor.upb.c
index 1b03b67..339fafa 100644
--- a/cmake/google/protobuf/descriptor.upb.c
+++ b/cmake/google/protobuf/descriptor.upb.c
@@ -23,7 +23,7 @@
const upb_msglayout google_protobuf_FileDescriptorSet_msginit = {
&google_protobuf_FileDescriptorSet_submsgs[0],
&google_protobuf_FileDescriptorSet__fields[0],
- UPB_SIZE(4, 8), 1, false,
+ UPB_SIZE(8, 8), 1, false, 255,
};
static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = {
@@ -43,17 +43,17 @@
{5, UPB_SIZE(44, 88), 0, 1, 11, 3},
{6, UPB_SIZE(48, 96), 0, 4, 11, 3},
{7, UPB_SIZE(52, 104), 0, 2, 11, 3},
- {8, UPB_SIZE(28, 56), 4, 3, 11, 1},
- {9, UPB_SIZE(32, 64), 5, 5, 11, 1},
+ {8, UPB_SIZE(28, 56), 3, 3, 11, 1},
+ {9, UPB_SIZE(32, 64), 4, 5, 11, 1},
{10, UPB_SIZE(56, 112), 0, 0, 5, 3},
{11, UPB_SIZE(60, 120), 0, 0, 5, 3},
- {12, UPB_SIZE(20, 40), 3, 0, 12, 1},
+ {12, UPB_SIZE(20, 40), 5, 0, 12, 1},
};
const upb_msglayout google_protobuf_FileDescriptorProto_msginit = {
&google_protobuf_FileDescriptorProto_submsgs[0],
&google_protobuf_FileDescriptorProto__fields[0],
- UPB_SIZE(64, 128), 12, false,
+ UPB_SIZE(64, 128), 12, false, 255,
};
static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[7] = {
@@ -82,7 +82,7 @@
const upb_msglayout google_protobuf_DescriptorProto_msginit = {
&google_protobuf_DescriptorProto_submsgs[0],
&google_protobuf_DescriptorProto__fields[0],
- UPB_SIZE(48, 96), 10, false,
+ UPB_SIZE(48, 96), 10, false, 255,
};
static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = {
@@ -98,7 +98,7 @@
const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = {
&google_protobuf_DescriptorProto_ExtensionRange_submsgs[0],
&google_protobuf_DescriptorProto_ExtensionRange__fields[0],
- UPB_SIZE(16, 24), 3, false,
+ UPB_SIZE(16, 24), 3, false, 255,
};
static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = {
@@ -109,7 +109,7 @@
const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = {
NULL,
&google_protobuf_DescriptorProto_ReservedRange__fields[0],
- UPB_SIZE(12, 12), 2, false,
+ UPB_SIZE(16, 16), 2, false, 255,
};
static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = {
@@ -123,7 +123,7 @@
const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = {
&google_protobuf_ExtensionRangeOptions_submsgs[0],
&google_protobuf_ExtensionRangeOptions__fields[0],
- UPB_SIZE(4, 8), 1, false,
+ UPB_SIZE(8, 8), 1, false, 255,
};
static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = {
@@ -131,23 +131,23 @@
};
static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = {
- {1, UPB_SIZE(24, 24), 6, 0, 12, 1},
- {2, UPB_SIZE(32, 40), 7, 0, 12, 1},
+ {1, UPB_SIZE(24, 24), 1, 0, 12, 1},
+ {2, UPB_SIZE(32, 40), 2, 0, 12, 1},
{3, UPB_SIZE(12, 12), 3, 0, 5, 1},
- {4, UPB_SIZE(4, 4), 1, 0, 14, 1},
- {5, UPB_SIZE(8, 8), 2, 0, 14, 1},
- {6, UPB_SIZE(40, 56), 8, 0, 12, 1},
- {7, UPB_SIZE(48, 72), 9, 0, 12, 1},
- {8, UPB_SIZE(64, 104), 11, 0, 11, 1},
- {9, UPB_SIZE(16, 16), 4, 0, 5, 1},
+ {4, UPB_SIZE(4, 4), 4, 0, 14, 1},
+ {5, UPB_SIZE(8, 8), 5, 0, 14, 1},
+ {6, UPB_SIZE(40, 56), 6, 0, 12, 1},
+ {7, UPB_SIZE(48, 72), 7, 0, 12, 1},
+ {8, UPB_SIZE(64, 104), 8, 0, 11, 1},
+ {9, UPB_SIZE(16, 16), 9, 0, 5, 1},
{10, UPB_SIZE(56, 88), 10, 0, 12, 1},
- {17, UPB_SIZE(20, 20), 5, 0, 8, 1},
+ {17, UPB_SIZE(20, 20), 11, 0, 8, 1},
};
const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = {
&google_protobuf_FieldDescriptorProto_submsgs[0],
&google_protobuf_FieldDescriptorProto__fields[0],
- UPB_SIZE(72, 112), 11, false,
+ UPB_SIZE(72, 112), 11, false, 255,
};
static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = {
@@ -162,7 +162,7 @@
const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = {
&google_protobuf_OneofDescriptorProto_submsgs[0],
&google_protobuf_OneofDescriptorProto__fields[0],
- UPB_SIZE(16, 32), 2, false,
+ UPB_SIZE(16, 32), 2, false, 255,
};
static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = {
@@ -182,7 +182,7 @@
const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = {
&google_protobuf_EnumDescriptorProto_submsgs[0],
&google_protobuf_EnumDescriptorProto__fields[0],
- UPB_SIZE(32, 64), 5, false,
+ UPB_SIZE(32, 64), 5, false, 255,
};
static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = {
@@ -193,7 +193,7 @@
const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = {
NULL,
&google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0],
- UPB_SIZE(12, 12), 2, false,
+ UPB_SIZE(16, 16), 2, false, 255,
};
static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = {
@@ -201,15 +201,15 @@
};
static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = {
- {1, UPB_SIZE(8, 8), 2, 0, 12, 1},
- {2, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {1, UPB_SIZE(8, 8), 1, 0, 12, 1},
+ {2, UPB_SIZE(4, 4), 2, 0, 5, 1},
{3, UPB_SIZE(16, 24), 3, 0, 11, 1},
};
const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = {
&google_protobuf_EnumValueDescriptorProto_submsgs[0],
&google_protobuf_EnumValueDescriptorProto__fields[0],
- UPB_SIZE(24, 32), 3, false,
+ UPB_SIZE(24, 32), 3, false, 255,
};
static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = {
@@ -226,7 +226,7 @@
const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = {
&google_protobuf_ServiceDescriptorProto_submsgs[0],
&google_protobuf_ServiceDescriptorProto__fields[0],
- UPB_SIZE(24, 48), 3, false,
+ UPB_SIZE(24, 48), 3, false, 255,
};
static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = {
@@ -234,18 +234,18 @@
};
static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = {
- {1, UPB_SIZE(4, 8), 3, 0, 12, 1},
- {2, UPB_SIZE(12, 24), 4, 0, 12, 1},
- {3, UPB_SIZE(20, 40), 5, 0, 12, 1},
- {4, UPB_SIZE(28, 56), 6, 0, 11, 1},
- {5, UPB_SIZE(1, 1), 1, 0, 8, 1},
- {6, UPB_SIZE(2, 2), 2, 0, 8, 1},
+ {1, UPB_SIZE(4, 8), 1, 0, 12, 1},
+ {2, UPB_SIZE(12, 24), 2, 0, 12, 1},
+ {3, UPB_SIZE(20, 40), 3, 0, 12, 1},
+ {4, UPB_SIZE(28, 56), 4, 0, 11, 1},
+ {5, UPB_SIZE(1, 1), 5, 0, 8, 1},
+ {6, UPB_SIZE(2, 2), 6, 0, 8, 1},
};
const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = {
&google_protobuf_MethodDescriptorProto_submsgs[0],
&google_protobuf_MethodDescriptorProto__fields[0],
- UPB_SIZE(32, 64), 6, false,
+ UPB_SIZE(32, 64), 6, false, 255,
};
static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = {
@@ -253,24 +253,24 @@
};
static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = {
- {1, UPB_SIZE(20, 24), 11, 0, 12, 1},
- {8, UPB_SIZE(28, 40), 12, 0, 12, 1},
- {9, UPB_SIZE(4, 4), 1, 0, 14, 1},
- {10, UPB_SIZE(8, 8), 2, 0, 8, 1},
- {11, UPB_SIZE(36, 56), 13, 0, 12, 1},
- {16, UPB_SIZE(9, 9), 3, 0, 8, 1},
- {17, UPB_SIZE(10, 10), 4, 0, 8, 1},
- {18, UPB_SIZE(11, 11), 5, 0, 8, 1},
- {20, UPB_SIZE(12, 12), 6, 0, 8, 1},
- {23, UPB_SIZE(13, 13), 7, 0, 8, 1},
- {27, UPB_SIZE(14, 14), 8, 0, 8, 1},
- {31, UPB_SIZE(15, 15), 9, 0, 8, 1},
- {36, UPB_SIZE(44, 72), 14, 0, 12, 1},
- {37, UPB_SIZE(52, 88), 15, 0, 12, 1},
- {39, UPB_SIZE(60, 104), 16, 0, 12, 1},
- {40, UPB_SIZE(68, 120), 17, 0, 12, 1},
- {41, UPB_SIZE(76, 136), 18, 0, 12, 1},
- {42, UPB_SIZE(16, 16), 10, 0, 8, 1},
+ {1, UPB_SIZE(20, 24), 1, 0, 12, 1},
+ {8, UPB_SIZE(28, 40), 2, 0, 12, 1},
+ {9, UPB_SIZE(4, 4), 3, 0, 14, 1},
+ {10, UPB_SIZE(8, 8), 4, 0, 8, 1},
+ {11, UPB_SIZE(36, 56), 5, 0, 12, 1},
+ {16, UPB_SIZE(9, 9), 6, 0, 8, 1},
+ {17, UPB_SIZE(10, 10), 7, 0, 8, 1},
+ {18, UPB_SIZE(11, 11), 8, 0, 8, 1},
+ {20, UPB_SIZE(12, 12), 9, 0, 8, 1},
+ {23, UPB_SIZE(13, 13), 10, 0, 8, 1},
+ {27, UPB_SIZE(14, 14), 11, 0, 8, 1},
+ {31, UPB_SIZE(15, 15), 12, 0, 8, 1},
+ {36, UPB_SIZE(44, 72), 13, 0, 12, 1},
+ {37, UPB_SIZE(52, 88), 14, 0, 12, 1},
+ {39, UPB_SIZE(60, 104), 15, 0, 12, 1},
+ {40, UPB_SIZE(68, 120), 16, 0, 12, 1},
+ {41, UPB_SIZE(76, 136), 17, 0, 12, 1},
+ {42, UPB_SIZE(16, 16), 18, 0, 8, 1},
{44, UPB_SIZE(84, 152), 19, 0, 12, 1},
{45, UPB_SIZE(92, 168), 20, 0, 12, 1},
{999, UPB_SIZE(100, 184), 0, 0, 11, 3},
@@ -279,7 +279,7 @@
const upb_msglayout google_protobuf_FileOptions_msginit = {
&google_protobuf_FileOptions_submsgs[0],
&google_protobuf_FileOptions__fields[0],
- UPB_SIZE(104, 192), 21, false,
+ UPB_SIZE(104, 192), 21, false, 255,
};
static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = {
@@ -297,7 +297,7 @@
const upb_msglayout google_protobuf_MessageOptions_msginit = {
&google_protobuf_MessageOptions_submsgs[0],
&google_protobuf_MessageOptions__fields[0],
- UPB_SIZE(12, 16), 5, false,
+ UPB_SIZE(16, 16), 5, false, 255,
};
static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = {
@@ -306,10 +306,10 @@
static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = {
{1, UPB_SIZE(4, 4), 1, 0, 14, 1},
- {2, UPB_SIZE(12, 12), 3, 0, 8, 1},
- {3, UPB_SIZE(13, 13), 4, 0, 8, 1},
- {5, UPB_SIZE(14, 14), 5, 0, 8, 1},
- {6, UPB_SIZE(8, 8), 2, 0, 14, 1},
+ {2, UPB_SIZE(12, 12), 2, 0, 8, 1},
+ {3, UPB_SIZE(13, 13), 3, 0, 8, 1},
+ {5, UPB_SIZE(14, 14), 4, 0, 8, 1},
+ {6, UPB_SIZE(8, 8), 5, 0, 14, 1},
{10, UPB_SIZE(15, 15), 6, 0, 8, 1},
{999, UPB_SIZE(16, 16), 0, 0, 11, 3},
};
@@ -317,7 +317,7 @@
const upb_msglayout google_protobuf_FieldOptions_msginit = {
&google_protobuf_FieldOptions_submsgs[0],
&google_protobuf_FieldOptions__fields[0],
- UPB_SIZE(20, 24), 7, false,
+ UPB_SIZE(24, 24), 7, false, 255,
};
static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = {
@@ -331,7 +331,7 @@
const upb_msglayout google_protobuf_OneofOptions_msginit = {
&google_protobuf_OneofOptions_submsgs[0],
&google_protobuf_OneofOptions__fields[0],
- UPB_SIZE(4, 8), 1, false,
+ UPB_SIZE(8, 8), 1, false, 255,
};
static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = {
@@ -347,7 +347,7 @@
const upb_msglayout google_protobuf_EnumOptions_msginit = {
&google_protobuf_EnumOptions_submsgs[0],
&google_protobuf_EnumOptions__fields[0],
- UPB_SIZE(8, 16), 3, false,
+ UPB_SIZE(8, 16), 3, false, 255,
};
static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = {
@@ -362,7 +362,7 @@
const upb_msglayout google_protobuf_EnumValueOptions_msginit = {
&google_protobuf_EnumValueOptions_submsgs[0],
&google_protobuf_EnumValueOptions__fields[0],
- UPB_SIZE(8, 16), 2, false,
+ UPB_SIZE(8, 16), 2, false, 255,
};
static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = {
@@ -377,7 +377,7 @@
const upb_msglayout google_protobuf_ServiceOptions_msginit = {
&google_protobuf_ServiceOptions_submsgs[0],
&google_protobuf_ServiceOptions__fields[0],
- UPB_SIZE(8, 16), 2, false,
+ UPB_SIZE(8, 16), 2, false, 255,
};
static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = {
@@ -385,15 +385,15 @@
};
static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = {
- {33, UPB_SIZE(8, 8), 2, 0, 8, 1},
- {34, UPB_SIZE(4, 4), 1, 0, 14, 1},
+ {33, UPB_SIZE(8, 8), 1, 0, 8, 1},
+ {34, UPB_SIZE(4, 4), 2, 0, 14, 1},
{999, UPB_SIZE(12, 16), 0, 0, 11, 3},
};
const upb_msglayout google_protobuf_MethodOptions_msginit = {
&google_protobuf_MethodOptions_submsgs[0],
&google_protobuf_MethodOptions__fields[0],
- UPB_SIZE(16, 24), 3, false,
+ UPB_SIZE(16, 24), 3, false, 255,
};
static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = {
@@ -402,10 +402,10 @@
static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = {
{2, UPB_SIZE(56, 80), 0, 0, 11, 3},
- {3, UPB_SIZE(32, 32), 4, 0, 12, 1},
- {4, UPB_SIZE(8, 8), 1, 0, 4, 1},
- {5, UPB_SIZE(16, 16), 2, 0, 3, 1},
- {6, UPB_SIZE(24, 24), 3, 0, 1, 1},
+ {3, UPB_SIZE(32, 32), 1, 0, 12, 1},
+ {4, UPB_SIZE(8, 8), 2, 0, 4, 1},
+ {5, UPB_SIZE(16, 16), 3, 0, 3, 1},
+ {6, UPB_SIZE(24, 24), 4, 0, 1, 1},
{7, UPB_SIZE(40, 48), 5, 0, 12, 1},
{8, UPB_SIZE(48, 64), 6, 0, 12, 1},
};
@@ -413,18 +413,18 @@
const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
&google_protobuf_UninterpretedOption_submsgs[0],
&google_protobuf_UninterpretedOption__fields[0],
- UPB_SIZE(64, 96), 7, false,
+ UPB_SIZE(64, 96), 7, false, 255,
};
static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = {
- {1, UPB_SIZE(4, 8), 2, 0, 12, 2},
- {2, UPB_SIZE(1, 1), 1, 0, 8, 2},
+ {1, UPB_SIZE(4, 8), 1, 0, 12, 2},
+ {2, UPB_SIZE(1, 1), 2, 0, 8, 2},
};
const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = {
NULL,
&google_protobuf_UninterpretedOption_NamePart__fields[0],
- UPB_SIZE(16, 32), 2, false,
+ UPB_SIZE(16, 32), 2, false, 255,
};
static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = {
@@ -438,7 +438,7 @@
const upb_msglayout google_protobuf_SourceCodeInfo_msginit = {
&google_protobuf_SourceCodeInfo_submsgs[0],
&google_protobuf_SourceCodeInfo__fields[0],
- UPB_SIZE(4, 8), 1, false,
+ UPB_SIZE(8, 8), 1, false, 255,
};
static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = {
@@ -452,7 +452,7 @@
const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = {
NULL,
&google_protobuf_SourceCodeInfo_Location__fields[0],
- UPB_SIZE(32, 64), 5, false,
+ UPB_SIZE(32, 64), 5, false, 255,
};
static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = {
@@ -466,20 +466,20 @@
const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = {
&google_protobuf_GeneratedCodeInfo_submsgs[0],
&google_protobuf_GeneratedCodeInfo__fields[0],
- UPB_SIZE(4, 8), 1, false,
+ UPB_SIZE(8, 8), 1, false, 255,
};
static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
{1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED},
- {2, UPB_SIZE(12, 16), 3, 0, 12, 1},
- {3, UPB_SIZE(4, 4), 1, 0, 5, 1},
- {4, UPB_SIZE(8, 8), 2, 0, 5, 1},
+ {2, UPB_SIZE(12, 16), 1, 0, 12, 1},
+ {3, UPB_SIZE(4, 4), 2, 0, 5, 1},
+ {4, UPB_SIZE(8, 8), 3, 0, 5, 1},
};
const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = {
NULL,
&google_protobuf_GeneratedCodeInfo_Annotation__fields[0],
- UPB_SIZE(24, 48), 4, false,
+ UPB_SIZE(24, 48), 4, false, 255,
};
#include "upb/port_undef.inc"
diff --git a/cmake/google/protobuf/descriptor.upb.h b/cmake/google/protobuf/descriptor.upb.h
index c9a19fc..ccb902b 100644
--- a/cmake/google/protobuf/descriptor.upb.h
+++ b/cmake/google/protobuf/descriptor.upb.h
@@ -11,6 +11,7 @@
#include "upb/msg.h"
#include "upb/decode.h"
+#include "upb/decode_fast.h"
#include "upb/encode.h"
#include "upb/port_def.inc"
@@ -211,13 +212,13 @@
UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); }
UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(52, 104)); }
UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); }
-UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 4); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_FileOptions*); }
-UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 5); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 4); }
UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_SourceCodeInfo*); }
UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(56, 112), len); }
UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(60, 120), len); }
-UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 3); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 5); }
UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); }
UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
@@ -291,7 +292,7 @@
return sub;
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) {
- _upb_sethas(msg, 4);
+ _upb_sethas(msg, 3);
*UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_FileOptions*) = value;
}
UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
@@ -304,7 +305,7 @@
return sub;
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) {
- _upb_sethas(msg, 5);
+ _upb_sethas(msg, 4);
*UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_SourceCodeInfo*) = value;
}
UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
@@ -337,7 +338,7 @@
arena);
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 3);
+ _upb_sethas(msg, 5);
*UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value;
}
@@ -610,35 +611,35 @@
return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 6); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_strview); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 7); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_strview); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 4); }
UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 5); }
UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 8); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 6); }
UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_strview); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 9); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 7); }
UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_strview); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 11); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 8); }
UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(64, 104), const google_protobuf_FieldOptions*); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 4); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 9); }
UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 10); }
UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_strview); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 5); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 11); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); }
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 6);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 7);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
@@ -646,23 +647,23 @@
*UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 4);
*UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 5);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 8);
+ _upb_sethas(msg, 6);
*UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 9);
+ _upb_sethas(msg, 7);
*UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) {
- _upb_sethas(msg, 11);
+ _upb_sethas(msg, 8);
*UPB_PTR_AT(msg, UPB_SIZE(64, 104), google_protobuf_FieldOptions*) = value;
}
UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_arena *arena) {
@@ -675,7 +676,7 @@
return sub;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
- _upb_sethas(msg, 4);
+ _upb_sethas(msg, 9);
*UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
@@ -683,7 +684,7 @@
*UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) {
- _upb_sethas(msg, 5);
+ _upb_sethas(msg, 11);
*UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = value;
}
@@ -844,19 +845,19 @@
return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview); }
-UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); }
UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) {
@@ -939,33 +940,33 @@
return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 3); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 4); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 5); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 6); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 4); }
UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 5); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 6); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 3);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 4);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 5);
+ _upb_sethas(msg, 3);
*UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) {
- _upb_sethas(msg, 6);
+ _upb_sethas(msg, 4);
*UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = value;
}
UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_arena *arena) {
@@ -978,11 +979,11 @@
return sub;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 5);
*UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 6);
*UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
}
@@ -1000,41 +1001,41 @@
return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 11); }
+UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 12); }
+UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
-UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 4); }
UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 13); }
+UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 5); }
UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 3); }
+UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 6); }
UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(9, 9), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 4); }
+UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 7); }
UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(10, 10), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 5); }
+UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 8); }
UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(11, 11), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 6); }
+UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 9); }
UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 7); }
+UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 10); }
UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 8); }
+UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 11); }
UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 9); }
+UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 12); }
UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool); }
-UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 14); }
+UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 13); }
UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 15); }
+UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 14); }
UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 16); }
+UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 15); }
UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 17); }
+UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 16); }
UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 18); }
+UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 17); }
UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_strview); }
-UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 10); }
+UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 18); }
UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 19); }
UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_strview); }
@@ -1044,75 +1045,75 @@
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(100, 184), len); }
UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 11);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 12);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 3);
*UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 4);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 13);
+ _upb_sethas(msg, 5);
*UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 3);
+ _upb_sethas(msg, 6);
*UPB_PTR_AT(msg, UPB_SIZE(9, 9), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 4);
+ _upb_sethas(msg, 7);
*UPB_PTR_AT(msg, UPB_SIZE(10, 10), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 5);
+ _upb_sethas(msg, 8);
*UPB_PTR_AT(msg, UPB_SIZE(11, 11), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 6);
+ _upb_sethas(msg, 9);
*UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 7);
+ _upb_sethas(msg, 10);
*UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 8);
+ _upb_sethas(msg, 11);
*UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 9);
+ _upb_sethas(msg, 12);
*UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 14);
+ _upb_sethas(msg, 13);
*UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 15);
+ _upb_sethas(msg, 14);
*UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 16);
+ _upb_sethas(msg, 15);
*UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 17);
+ _upb_sethas(msg, 16);
*UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
- _upb_sethas(msg, 18);
+ _upb_sethas(msg, 17);
*UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) {
- _upb_sethas(msg, 10);
+ _upb_sethas(msg, 18);
*UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
@@ -1208,13 +1209,13 @@
UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
-UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 3); }
+UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool); }
-UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 4); }
+UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool); }
-UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 5); }
+UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 4); }
UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool); }
-UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 5); }
UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 6); }
UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool); }
@@ -1226,19 +1227,19 @@
*UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) {
- _upb_sethas(msg, 3);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) {
- _upb_sethas(msg, 4);
+ _upb_sethas(msg, 3);
*UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) {
- _upb_sethas(msg, 5);
+ _upb_sethas(msg, 4);
*UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 5);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) {
@@ -1421,19 +1422,19 @@
return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool); }
-UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 16)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(12, 16), len); }
UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool) = value;
}
UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) {
@@ -1466,13 +1467,13 @@
UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(56, 80)); }
UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg, size_t *len) { return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_accessor(msg, UPB_SIZE(56, 80), len); }
-UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 4); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview); }
-UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t); }
-UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t); }
-UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 3); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 4); }
UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 5); }
UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview); }
@@ -1493,19 +1494,19 @@
return sub;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
- _upb_sethas(msg, 4);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 3);
*UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) {
- _upb_sethas(msg, 3);
+ _upb_sethas(msg, 4);
*UPB_PTR_AT(msg, UPB_SIZE(24, 24), double) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
@@ -1531,17 +1532,17 @@
return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
-UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
@@ -1683,11 +1684,11 @@
}
UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 32), len); }
-UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 3); }
+UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 1); }
UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview); }
-UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 1); }
+UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 2); }
UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
-UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 2); }
+UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 3); }
UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) {
@@ -1701,15 +1702,15 @@
arena);
}
UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) {
- _upb_sethas(msg, 3);
+ _upb_sethas(msg, 1);
*UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview) = value;
}
UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
- _upb_sethas(msg, 1);
+ _upb_sethas(msg, 2);
*UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
- _upb_sethas(msg, 2);
+ _upb_sethas(msg, 3);
*UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
diff --git a/cmake/make_cmakelists.py b/cmake/make_cmakelists.py
index ee9760a..035debb 100755
--- a/cmake/make_cmakelists.py
+++ b/cmake/make_cmakelists.py
@@ -144,6 +144,9 @@
def config_setting(self, **kwargs):
pass
+ def upb_fasttable_enabled(self, **kwargs):
+ pass
+
def select(self, arg_dict):
return []
@@ -280,6 +283,7 @@
exec(open("WORKSPACE").read(), GetDict(WorkspaceFileFunctions(converter)))
exec(open("BUILD").read(), GetDict(BuildFileFunctions(converter)))
+exec(open("third_party/wyhash/BUILD").read(), GetDict(BuildFileFunctions(converter)))
with open(sys.argv[1], "w") as f:
f.write(converter.convert())
diff --git a/examples/bazel/BUILD b/examples/bazel/BUILD
index af2c6f8..9711925 100644
--- a/examples/bazel/BUILD
+++ b/examples/bazel/BUILD
@@ -16,6 +16,6 @@
cc_binary(
name = "test_binary",
srcs = ["test_binary.c"],
- deps = [":foo_upbproto"],
copts = ["-std=c99"],
+ deps = [":foo_upbproto"],
)
diff --git a/kokoro/ubuntu/build.sh b/kokoro/ubuntu/build.sh
index 9ea1e67..c95ee88 100644
--- a/kokoro/ubuntu/build.sh
+++ b/kokoro/ubuntu/build.sh
@@ -20,8 +20,11 @@
if which gcc; then
gcc --version
- CC=gcc bazel test --test_output=errors ...
- CC=gcc bazel test -c opt --test_output=errors ...
+ CC=gcc bazel test -c opt --test_output=errors ... -- -benchmarks:benchmark
+ if [[ $(uname) = "Linux" ]]; then
+ CC=gcc bazel test --test_output=errors ...
+ CC=gcc bazel test --test_output=errors ... --//:fasttable_enabled=true -- -cmake:test_generated_files -benchmarks:benchmark
+ fi
# TODO: work through these errors and enable this.
# if gcc -fanalyzer -x c /dev/null -c -o /dev/null; then
# CC=gcc bazel test --copt=-fanalyzer --test_output=errors ...
@@ -29,12 +32,13 @@
fi
if which clang; then
- CC=clang bazel test --test_output=errors ...
- CC=clang bazel test --test_output=errors -c opt ...
-
if [[ $(uname) = "Linux" ]]; then
- CC=clang bazel test --test_output=errors --config=m32 ...
- CC=clang bazel test --test_output=errors --config=asan ...
+ CC=clang bazel test --test_output=errors ...
+ CC=clang bazel test --test_output=errors -c opt ... -- -benchmarks:benchmark
+ CC=clang bazel test --test_output=errors ... --//:fasttable_enabled=true -- -cmake:test_generated_files
+
+ CC=clang bazel test --test_output=errors --config=m32 ... -- -benchmarks:benchmark
+ CC=clang bazel test --test_output=errors --config=asan ... -- -benchmarks:benchmark
# TODO: update to a newer Lua that hopefully does not trigger UBSAN.
CC=clang bazel test --test_output=errors --config=ubsan ... -- -tests/bindings/lua:test_lua
diff --git a/tests/bindings/lua/BUILD b/tests/bindings/lua/BUILD
index 00eb3ba..8834feb 100644
--- a/tests/bindings/lua/BUILD
+++ b/tests/bindings/lua/BUILD
@@ -12,6 +12,7 @@
cc_test(
name = "test_lua",
srcs = ["main.c"],
+ copts = UPB_DEFAULT_COPTS,
data = [
"test_upb.lua",
":descriptor_proto_lua",
@@ -24,7 +25,6 @@
"@com_google_protobuf//:conformance_proto",
"@com_google_protobuf//:descriptor_proto",
],
- copts = UPB_DEFAULT_COPTS,
linkstatic = 1,
deps = [
"//upb/bindings/lua:lupb",
diff --git a/tests/bindings/lua/test.proto b/tests/bindings/lua/test.proto
index c4b7e9c..2803835 100644
--- a/tests/bindings/lua/test.proto
+++ b/tests/bindings/lua/test.proto
@@ -6,3 +6,19 @@
message MapTest {
map<string, double> map_string_double = 1;
}
+
+message PackedTest {
+ repeated bool bool_packed = 1 [packed = true];
+ repeated int32 i32_packed = 2 [packed = true];
+ repeated int64 i64_packed = 3 [packed = true];
+ repeated fixed32 f32_packed = 4 [packed = true];
+ repeated fixed64 f64_packed = 5 [packed = true];
+}
+
+message UnpackedTest {
+ repeated bool bool_packed = 1 [packed = false];
+ repeated int32 i32_packed = 2 [packed = false];
+ repeated int64 i64_packed = 3 [packed = false];
+ repeated fixed32 f32_packed = 4 [packed = false];
+ repeated fixed64 f64_packed = 5 [packed = false];
+}
diff --git a/tests/bindings/lua/test_upb.lua b/tests/bindings/lua/test_upb.lua
index 9d8efa2..84178aa 100644
--- a/tests/bindings/lua/test_upb.lua
+++ b/tests/bindings/lua/test_upb.lua
@@ -133,6 +133,65 @@
assert_equal(2.5, msg2.map_string_double["two point five"])
end
+function test_string_double_map()
+ local function fill_msg(msg)
+ msg.i32_packed[1] = 100
+ msg.i32_packed[2] = 200
+ msg.i32_packed[3] = 50000
+
+ msg.i64_packed[1] = 101
+ msg.i64_packed[2] = 201
+ msg.i64_packed[3] = 50001
+
+ msg.f32_packed[1] = 102
+ msg.f32_packed[2] = 202
+ msg.f32_packed[3] = 50002
+
+ msg.f64_packed[1] = 103
+ msg.f64_packed[2] = 203
+ msg.f64_packed[3] = 50003
+ end
+
+ local function check_msg(msg)
+ assert_equal(100, msg.i32_packed[1])
+ assert_equal(200, msg.i32_packed[2])
+ assert_equal(50000, msg.i32_packed[3])
+ assert_equal(3, #msg.i32_packed)
+
+ assert_equal(101, msg.i64_packed[1])
+ assert_equal(201, msg.i64_packed[2])
+ assert_equal(50001, msg.i64_packed[3])
+ assert_equal(3, #msg.i64_packed)
+
+ assert_equal(102, msg.f32_packed[1])
+ assert_equal(202, msg.f32_packed[2])
+ assert_equal(50002, msg.f32_packed[3])
+ assert_equal(3, #msg.f32_packed)
+
+ assert_equal(103, msg.f64_packed[1])
+ assert_equal(203, msg.f64_packed[2])
+ assert_equal(50003, msg.f64_packed[3])
+ assert_equal(3, #msg.f64_packed)
+ end
+
+ local msg = upb_test.PackedTest()
+ fill_msg(msg)
+ check_msg(msg)
+
+ local serialized_packed = upb.encode(msg)
+ local msg2 = upb.decode(upb_test.PackedTest, serialized_packed)
+ local msg3 = upb.decode(upb_test.UnpackedTest, serialized_packed)
+ check_msg(msg2)
+ check_msg(msg3)
+
+ serialized_unpacked = upb.encode(msg3)
+ local msg4 = upb.decode(upb_test.PackedTest, serialized_unpacked)
+ local msg5 = upb.decode(upb_test.PackedTest, serialized_unpacked)
+ check_msg(msg4)
+ check_msg(msg5)
+
+end
+
function test_msg_string_map()
msg = test_messages_proto3.TestAllTypesProto3()
msg.map_string_string["foo"] = "bar"
@@ -297,6 +356,22 @@
},
}
+function test_utf8()
+ local invalid_utf8 = "\xff"
+ local proto2_msg = test_messages_proto2.TestAllTypesProto2{
+ optional_string = invalid_utf8,
+ }
+
+ -- As proto2, invalid UTF-8 parses and serializes fine.
+ local serialized = upb.encode(proto2_msg)
+ local proto2_msg2 = upb.decode(test_messages_proto2.TestAllTypesProto2, serialized)
+
+ -- Decoding as proto3 fails.
+ assert_error(function()
+ upb.decode(test_messages_proto3.TestAllTypesProto3, serialized)
+ end)
+end
+
function test_msg_primitives()
local msg = test_messages_proto3.TestAllTypesProto3{
optional_int32 = 10,
@@ -482,7 +557,7 @@
end
function test_unknown()
- local bytes = string.rep("\x38\x00", 10000)
+ local bytes = string.rep("\x38\x00", 1000)
for i=1,1000 do
local msg = upb.decode(test_messages_proto3.TestAllTypesProto3, bytes)
end
diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c
index fe9f522..f444180 100644
--- a/tests/conformance_upb.c
+++ b/tests/conformance_upb.c
@@ -201,6 +201,16 @@
upb_msg *msg;
upb_strview name = conformance_ConformanceRequest_message_type(c->request);
const upb_msgdef *m = upb_symtab_lookupmsg2(c->symtab, name.data, name.size);
+#if 0
+ // Handy code for limiting conformance tests to a single input payload.
+ // This is a hack since the conformance runner doesn't give an easy way to
+ // specify what test should be run.
+ const char skip[] = "\343>\010\301\002\344>\230?\001\230?\002\230?\003";
+ upb_strview skip_str = upb_strview_make(skip, sizeof(skip) - 1);
+ upb_strview pb_payload =
+ conformance_ConformanceRequest_protobuf_payload(c->request);
+ if (!upb_strview_eql(pb_payload, skip_str)) m = NULL;
+#endif
if (!m) {
static const char msg[] = "Unknown message type.";
@@ -286,6 +296,7 @@
if (!DoTestIo(symtab)) {
fprintf(stderr, "conformance_upb: received EOF from test runner "
"after %d tests, exiting\n", test_count);
+ upb_symtab_free(symtab);
return 0;
}
}
diff --git a/tests/test_generated_code.c b/tests/test_generated_code.c
index 1cfeb27..bd1066b 100644
--- a/tests/test_generated_code.c
+++ b/tests/test_generated_code.c
@@ -30,6 +30,7 @@
protobuf_test_messages_proto3_TestAllTypesProto3_new(arena);
protobuf_test_messages_proto3_TestAllTypesProto3 *msg2;
upb_strview serialized;
+ upb_strview val;
protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int32(msg, 10);
protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int64(msg, 20);
@@ -61,9 +62,30 @@
msg2) - 60.6 < 0.01);
ASSERT(protobuf_test_messages_proto3_TestAllTypesProto3_optional_bool(
msg2) == 1);
- ASSERT(upb_strview_eql(
- protobuf_test_messages_proto3_TestAllTypesProto3_optional_string(msg2),
- test_str_view));
+ val = protobuf_test_messages_proto3_TestAllTypesProto3_optional_string(msg2);
+ ASSERT(upb_strview_eql(val, test_str_view));
+
+ upb_arena_free(arena);
+}
+
+static void test_utf8(void) {
+ const char invalid_utf8[] = "\xff";
+ const upb_strview invalid_utf8_view = upb_strview_make(invalid_utf8, 1);
+ upb_arena *arena = upb_arena_new();
+ upb_strview serialized;
+ protobuf_test_messages_proto3_TestAllTypesProto3 *msg =
+ protobuf_test_messages_proto3_TestAllTypesProto3_new(arena);
+ protobuf_test_messages_proto3_TestAllTypesProto3 *msg2;
+
+ protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_string(
+ msg, invalid_utf8_view);
+
+ serialized.data = protobuf_test_messages_proto3_TestAllTypesProto3_serialize(
+ msg, arena, &serialized.size);
+
+ msg2 = protobuf_test_messages_proto3_TestAllTypesProto3_parse(
+ serialized.data, serialized.size, arena);
+ ASSERT(msg2 == NULL);
upb_arena_free(arena);
}
@@ -390,6 +412,7 @@
int run_tests(int argc, char *argv[]) {
test_scalars();
+ test_utf8();
test_string_map();
test_string_double_map();
test_int32_map();
diff --git a/third_party/wyhash/BUILD b/third_party/wyhash/BUILD
new file mode 100644
index 0000000..f3f3a6f
--- /dev/null
+++ b/third_party/wyhash/BUILD
@@ -0,0 +1,17 @@
+licenses(["unencumbered"])
+
+exports_files(["LICENSE"])
+
+cc_library(
+ name = "wyhash",
+ hdrs = ["wyhash.h"],
+ visibility = ["//:__pkg__"],
+)
+
+filegroup(
+ name = "cmake_files",
+ srcs = glob([
+ "**/*",
+ ]),
+ visibility = ["//cmake:__pkg__"],
+)
diff --git a/upb/bindings/lua/lua_proto_library.bzl b/upb/bindings/lua/lua_proto_library.bzl
index 29b1caa..d6ac301 100644
--- a/upb/bindings/lua/lua_proto_library.bzl
+++ b/upb/bindings/lua/lua_proto_library.bzl
@@ -1,4 +1,3 @@
-
load("@bazel_skylib//lib:paths.bzl", "paths")
# Generic support code #########################################################
@@ -12,6 +11,7 @@
if short_path.startswith("../"):
second_slash = short_path.index("/", 3)
short_path = short_path[second_slash + 1:]
+
# Sometimes it has another few prefixes like:
# _virtual_imports/any_proto/google/protobuf/any.proto
# We want just google/protobuf/any.proto.
@@ -64,9 +64,10 @@
files = dep[_LuaFiles].files
return [
DefaultInfo(
- files = files,
- data_runfiles = ctx.runfiles(files = files.to_list())),
- ]
+ files = files,
+ data_runfiles = ctx.runfiles(files = files.to_list()),
+ ),
+ ]
def _lua_proto_library_aspect_impl(target, ctx):
proto_info = target[ProtoInfo]
diff --git a/upb/decode.c b/upb/decode.c
index 01997f2..d38b46d 100644
--- a/upb/decode.c
+++ b/upb/decode.c
@@ -4,6 +4,7 @@
#include <setjmp.h>
#include <string.h>
+#include "upb/decode.int.h"
#include "upb/upb.h"
#include "upb/upb.int.h"
@@ -137,19 +138,6 @@
OP_VARPCK_LG2(3), /* REPEATED SINT64 */
};
-/* Data pertaining to the parse. */
-typedef struct {
- const char *end; /* Can read up to 16 bytes slop beyond this. */
- const char *limit_ptr; /* = end + UPB_MIN(limit, 0) */
- int limit; /* Submessage limit relative to end. */
- int depth;
- uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */
- bool alias;
- char patch[32];
- upb_arena arena;
- jmp_buf err;
-} upb_decstate;
-
typedef union {
bool bool_val;
uint32_t uint32_val;
@@ -162,38 +150,27 @@
UPB_NORETURN static void decode_err(upb_decstate *d) { longjmp(d->err, 1); }
-void decode_verifyutf8(upb_decstate *d, const char *buf, int len) {
- static const uint8_t utf8_offset[] = {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0,
- };
+const char *fastdecode_err(upb_decstate *d) {
+ longjmp(d->err, 1);
+ return NULL;
+}
- int i, j;
- uint8_t offset;
+const uint8_t upb_utf8_offsets[] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0,
+};
- i = 0;
- while (i < len) {
- offset = utf8_offset[(uint8_t)buf[i]];
- if (offset == 0 || i + offset > len) {
- decode_err(d);
- }
- for (j = i + 1; j < i + offset; j++) {
- if ((buf[j] & 0xc0) != 0x80) {
- decode_err(d);
- }
- }
- i += offset;
- }
- if (i != len) decode_err(d);
+static void decode_verifyutf8(upb_decstate *d, const char *buf, int len) {
+ if (!decode_verifyutf8_inl(buf, len)) decode_err(d);
}
static bool decode_reserve(upb_decstate *d, upb_array *arr, size_t elem) {
@@ -298,55 +275,14 @@
return _upb_msg_new_inl(subl, &d->arena);
}
-static int decode_pushlimit(upb_decstate *d, const char *ptr, int size) {
- int limit = size + (int)(ptr - d->end);
- int delta = d->limit - limit;
- d->limit = limit;
- d->limit_ptr = d->end + UPB_MIN(0, limit);
- return delta;
-}
-
-static void decode_poplimit(upb_decstate *d, int saved_delta) {
- d->limit += saved_delta;
- d->limit_ptr = d->end + UPB_MIN(0, d->limit);
-}
-
-typedef struct {
- bool ok;
- const char *ptr;
-} decode_doneret;
-
UPB_NOINLINE
-static const char *decode_isdonefallback(upb_decstate *d, const char *ptr,
- int overrun) {
- if (overrun < d->limit) {
- /* Need to copy remaining data into patch buffer. */
- UPB_ASSERT(overrun < 16);
- memset(d->patch + 16, 0, 16);
- memcpy(d->patch, d->end, 16);
- ptr = &d->patch[0] + overrun;
- d->end = &d->patch[16];
- d->limit -= 16;
- d->limit_ptr = d->end + d->limit;
- d->alias = false;
- UPB_ASSERT(ptr < d->limit_ptr);
- return ptr;
- } else {
+const char *decode_isdonefallback(upb_decstate *d, const char *ptr,
+ int overrun) {
+ ptr = decode_isdonefallback_inl(d, ptr, overrun);
+ if (ptr == NULL) {
decode_err(d);
}
-}
-
-UPB_FORCEINLINE
-static bool decode_isdone(upb_decstate *d, const char **ptr) {
- int overrun = *ptr - d->end;
- if (UPB_LIKELY(*ptr < d->limit_ptr)) {
- return false;
- } else if (UPB_LIKELY(overrun == d->limit)) {
- return true;
- } else {
- *ptr = decode_isdonefallback(d, *ptr, overrun);
- return false;
- }
+ return ptr;
}
static const char *decode_readstr(upb_decstate *d, const char *ptr, int size,
@@ -363,30 +299,38 @@
return ptr + size;
}
+UPB_FORCEINLINE
static const char *decode_tosubmsg(upb_decstate *d, const char *ptr,
upb_msg *submsg, const upb_msglayout *layout,
const upb_msglayout_field *field, int size) {
const upb_msglayout *subl = layout->submsgs[field->submsg_index];
int saved_delta = decode_pushlimit(d, ptr, size);
if (--d->depth < 0) decode_err(d);
- ptr = decode_msg(d, ptr, submsg, subl);
- decode_poplimit(d, saved_delta);
- if (d->end_group != 0) decode_err(d);
+ if (!decode_isdone(d, &ptr)) {
+ ptr = decode_msg(d, ptr, submsg, subl);
+ }
+ if (d->end_group != DECODE_NOGROUP) decode_err(d);
+ decode_poplimit(d, ptr, saved_delta);
d->depth++;
return ptr;
}
+UPB_FORCEINLINE
static const char *decode_group(upb_decstate *d, const char *ptr,
upb_msg *submsg, const upb_msglayout *subl,
uint32_t number) {
if (--d->depth < 0) decode_err(d);
+ if (decode_isdone(d, &ptr)) {
+ decode_err(d);
+ }
ptr = decode_msg(d, ptr, submsg, subl);
if (d->end_group != number) decode_err(d);
- d->end_group = 0;
+ d->end_group = DECODE_NOGROUP;
d->depth++;
return ptr;
}
+UPB_FORCEINLINE
static const char *decode_togroup(upb_decstate *d, const char *ptr,
upb_msg *submsg, const upb_msglayout *layout,
const upb_msglayout_field *field) {
@@ -475,7 +419,7 @@
memcpy(out, &elem, scale);
out += scale;
}
- decode_poplimit(d, saved_limit);
+ decode_poplimit(d, ptr, saved_limit);
return ptr;
}
default:
@@ -574,9 +518,24 @@
return ptr;
}
+UPB_FORCEINLINE
+static bool decode_tryfastdispatch(upb_decstate *d, const char **ptr,
+ upb_msg *msg, const upb_msglayout *layout) {
+#if UPB_FASTTABLE
+ if (layout && layout->table_mask != (unsigned char)-1) {
+ uint16_t tag = fastdecode_loadtag(*ptr);
+ intptr_t table = decode_totable(layout);
+ *ptr = fastdecode_tagdispatch(d, *ptr, msg, table, 0, tag);
+ return true;
+ }
+#endif
+ return false;
+}
+
+UPB_NOINLINE
static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg,
const upb_msglayout *layout) {
- while (!decode_isdone(d, &ptr)) {
+ while (true) {
uint32_t tag;
const upb_msglayout_field *field;
int field_number;
@@ -585,6 +544,7 @@
wireval val;
int op;
+ UPB_ASSERT(ptr < d->limit_ptr);
ptr = decode_varint32(d, ptr, &tag);
field_number = tag >> 3;
wire_type = tag & 7;
@@ -652,20 +612,35 @@
unknown:
/* Skip unknown field. */
if (field_number == 0) decode_err(d);
- if (wire_type == UPB_WIRE_TYPE_START_GROUP) {
- ptr = decode_group(d, ptr, NULL, NULL, field_number);
- }
+ if (wire_type == UPB_WIRE_TYPE_DELIMITED) ptr += val.size;
if (msg) {
- if (wire_type == UPB_WIRE_TYPE_DELIMITED) ptr += val.size;
+ if (wire_type == UPB_WIRE_TYPE_START_GROUP) {
+ d->unknown = field_start;
+ d->unknown_msg = msg;
+ ptr = decode_group(d, ptr, NULL, NULL, field_number);
+ d->unknown_msg = NULL;
+ field_start = d->unknown;
+ }
if (!_upb_msg_addunknown(msg, field_start, ptr - field_start,
&d->arena)) {
decode_err(d);
}
+ } else if (wire_type == UPB_WIRE_TYPE_START_GROUP) {
+ ptr = decode_group(d, ptr, NULL, NULL, field_number);
}
}
- }
- return ptr;
+ if (decode_isdone(d, &ptr)) return ptr;
+ if (decode_tryfastdispatch(d, &ptr, msg, layout)) return ptr;
+ }
+}
+
+const char *fastdecode_generic(struct upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table, uint64_t hasbits,
+ uint64_t data) {
+ (void)data;
+ *(uint32_t*)msg |= hasbits;
+ return decode_msg(d, ptr, msg, decode_totablep(table));
}
bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
@@ -675,7 +650,7 @@
if (size == 0) {
return true;
- } else if (size < 16) {
+ } else if (size <= 16) {
memset(&state.patch, 0, 32);
memcpy(&state.patch, buf, size);
buf = state.patch;
@@ -689,8 +664,9 @@
}
state.limit_ptr = state.end;
+ state.unknown_msg = NULL;
state.depth = 64;
- state.end_group = 0;
+ state.end_group = DECODE_NOGROUP;
state.arena.head = arena->head;
state.arena.last_size = arena->last_size;
state.arena.parent = arena;
@@ -698,8 +674,10 @@
if (UPB_UNLIKELY(setjmp(state.err))) {
ok = false;
} else {
- decode_msg(&state, buf, msg, l);
- ok = state.end_group == 0;
+ if (!decode_tryfastdispatch(&state, &buf, msg, l)) {
+ decode_msg(&state, buf, msg, l);
+ }
+ ok = state.end_group == DECODE_NOGROUP;
}
arena->head.ptr = state.arena.head.ptr;
diff --git a/upb/decode.int.h b/upb/decode.int.h
new file mode 100644
index 0000000..e286b9c
--- /dev/null
+++ b/upb/decode.int.h
@@ -0,0 +1,163 @@
+/*
+** Internal implementation details of the decoder that are shared between
+** decode.c and decode_fast.c.
+*/
+
+#ifndef UPB_DECODE_INT_H_
+#define UPB_DECODE_INT_H_
+
+#include <setjmp.h>
+
+#include "upb/msg.h"
+#include "upb/upb.int.h"
+
+/* Must be last. */
+#include "upb/port_def.inc"
+
+#define DECODE_NOGROUP -1
+
+typedef struct upb_decstate {
+ const char *end; /* Can read up to 16 bytes slop beyond this. */
+ const char *limit_ptr; /* = end + UPB_MIN(limit, 0) */
+ upb_msg *unknown_msg; /* If non-NULL, add unknown data at buffer flip. */
+ const char *unknown; /* Start of unknown data. */
+ int limit; /* Submessage limit relative to end. */
+ int depth;
+ uint32_t end_group; /* field number of END_GROUP tag, else DECODE_NOGROUP */
+ bool alias;
+ char patch[32];
+ upb_arena arena;
+ jmp_buf err;
+} upb_decstate;
+
+/* Error function that will abort decoding with longjmp(). We can't declare this
+ * UPB_NORETURN, even though it is appropriate, because if we do then compilers
+ * will "helpfully" refuse to tailcall to it
+ * (see: https://stackoverflow.com/a/55657013), which will defeat a major goal
+ * of our optimizations. That is also why we must declare it in a separate file,
+ * otherwise the compiler will see that it calls longjmp() and deduce that it is
+ * noreturn. */
+const char *fastdecode_err(upb_decstate *d);
+
+extern const uint8_t upb_utf8_offsets[];
+
+UPB_INLINE
+bool decode_verifyutf8_inl(const char *buf, int len) {
+ int i, j;
+ uint8_t offset;
+
+ i = 0;
+ while (i < len) {
+ offset = upb_utf8_offsets[(uint8_t)buf[i]];
+ if (offset == 0 || i + offset > len) {
+ return false;
+ }
+ for (j = i + 1; j < i + offset; j++) {
+ if ((buf[j] & 0xc0) != 0x80) {
+ return false;
+ }
+ }
+ i += offset;
+ }
+ return i == len;
+}
+
+/* x86-64 pointers always have the high 16 bits matching. So we can shift
+ * left 8 and right 8 without loss of information. */
+UPB_INLINE intptr_t decode_totable(const upb_msglayout *tablep) {
+ return ((intptr_t)tablep << 8) | tablep->table_mask;
+}
+
+UPB_INLINE const upb_msglayout *decode_totablep(intptr_t table) {
+ return (const upb_msglayout*)(table >> 8);
+}
+
+UPB_INLINE
+const char *decode_isdonefallback_inl(upb_decstate *d, const char *ptr,
+ int overrun) {
+ if (overrun < d->limit) {
+ /* Need to copy remaining data into patch buffer. */
+ UPB_ASSERT(overrun < 16);
+ if (d->unknown_msg) {
+ if (!_upb_msg_addunknown(d->unknown_msg, d->unknown, ptr - d->unknown,
+ &d->arena)) {
+ return NULL;
+ }
+ d->unknown = &d->patch[0] + overrun;
+ }
+ memset(d->patch + 16, 0, 16);
+ memcpy(d->patch, d->end, 16);
+ ptr = &d->patch[0] + overrun;
+ d->end = &d->patch[16];
+ d->limit -= 16;
+ d->limit_ptr = d->end + d->limit;
+ d->alias = false;
+ UPB_ASSERT(ptr < d->limit_ptr);
+ return ptr;
+ } else {
+ return NULL;
+ }
+}
+
+const char *decode_isdonefallback(upb_decstate *d, const char *ptr,
+ int overrun);
+
+UPB_INLINE
+bool decode_isdone(upb_decstate *d, const char **ptr) {
+ int overrun = *ptr - d->end;
+ if (UPB_LIKELY(*ptr < d->limit_ptr)) {
+ return false;
+ } else if (UPB_LIKELY(overrun == d->limit)) {
+ return true;
+ } else {
+ *ptr = decode_isdonefallback(d, *ptr, overrun);
+ return false;
+ }
+}
+
+UPB_INLINE
+const char *fastdecode_tagdispatch(upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table,
+ uint64_t hasbits, uint32_t tag) {
+ const upb_msglayout *table_p = decode_totablep(table);
+ uint8_t mask = table;
+ uint64_t data;
+ size_t idx = tag & mask;
+ UPB_ASSUME((idx & 7) == 0);
+ idx >>= 3;
+ data = table_p->fasttable[idx].field_data ^ tag;
+ return table_p->fasttable[idx].field_parser(d, ptr, msg, table, hasbits, data);
+}
+
+UPB_INLINE uint32_t fastdecode_loadtag(const char* ptr) {
+ uint16_t tag;
+ memcpy(&tag, ptr, 2);
+ return tag;
+}
+
+UPB_INLINE void decode_checklimit(upb_decstate *d) {
+ UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit));
+}
+
+UPB_INLINE int decode_pushlimit(upb_decstate *d, const char *ptr, int size) {
+ int limit = size + (int)(ptr - d->end);
+ int delta = d->limit - limit;
+ decode_checklimit(d);
+ d->limit = limit;
+ d->limit_ptr = d->end + UPB_MIN(0, limit);
+ decode_checklimit(d);
+ return delta;
+}
+
+UPB_INLINE void decode_poplimit(upb_decstate *d, const char *ptr,
+ int saved_delta) {
+ UPB_ASSERT(ptr - d->end == d->limit);
+ decode_checklimit(d);
+ d->limit += saved_delta;
+ d->limit_ptr = d->end + UPB_MIN(0, d->limit);
+ decode_checklimit(d);
+}
+
+#include "upb/port_undef.inc"
+
+#endif /* UPB_DECODE_INT_H_ */
diff --git a/upb/decode_fast.c b/upb/decode_fast.c
new file mode 100644
index 0000000..f58f70e
--- /dev/null
+++ b/upb/decode_fast.c
@@ -0,0 +1,1040 @@
+// Fast decoder: ~3x the speed of decode.c, but x86-64 specific.
+// Also the table size grows by 2x.
+//
+// Could potentially be ported to ARM64 or other 64-bit archs that pass at
+// least six arguments in registers.
+//
+// The overall design is to create specialized functions for every possible
+// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch
+// to the specialized function as quickly as possible.
+
+#include "upb/decode_fast.h"
+
+#include "upb/decode.int.h"
+
+/* Must be last. */
+#include "upb/port_def.inc"
+
+#if UPB_FASTTABLE
+
+// The standard set of arguments passed to each parsing function.
+// Thanks to x86-64 calling conventions, these will stay in registers.
+#define UPB_PARSE_PARAMS \
+ upb_decstate *d, const char *ptr, upb_msg *msg, intptr_t table, \
+ uint64_t hasbits, uint64_t data
+
+#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data
+
+#define RETURN_GENERIC(m) \
+ /* fprintf(stderr, m); */ \
+ return fastdecode_generic(d, ptr, msg, table, hasbits, 0);
+
+typedef enum {
+ CARD_s = 0, /* Singular (optional, non-repeated) */
+ CARD_o = 1, /* Oneof */
+ CARD_r = 2, /* Repeated */
+ CARD_p = 3 /* Packed Repeated */
+} upb_card;
+
+UPB_NOINLINE
+static const char *fastdecode_isdonefallback(upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table,
+ uint64_t hasbits, int overrun) {
+ ptr = decode_isdonefallback_inl(d, ptr, overrun);
+ if (ptr == NULL) {
+ return fastdecode_err(d);
+ }
+ uint16_t tag = fastdecode_loadtag(ptr);
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, tag);
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_dispatch(upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table,
+ uint64_t hasbits) {
+ if (UPB_UNLIKELY(ptr >= d->limit_ptr)) {
+ int overrun = ptr - d->end;
+ if (UPB_LIKELY(overrun == d->limit)) {
+ // Parse is finished.
+ *(uint32_t*)msg |= hasbits; // Sync hasbits.
+ return ptr;
+ } else {
+ return fastdecode_isdonefallback(d, ptr, msg, table, hasbits, overrun);
+ }
+ }
+
+ // Read two bytes of tag data (for a one-byte tag, the high byte is junk).
+ uint16_t tag = fastdecode_loadtag(ptr);
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, tag);
+}
+
+UPB_FORCEINLINE
+static bool fastdecode_checktag(uint64_t data, int tagbytes) {
+ if (tagbytes == 1) {
+ return (data & 0xff) == 0;
+ } else {
+ return (data & 0xffff) == 0;
+ }
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_longsize(const char *ptr, int *size) {
+ int i;
+ UPB_ASSERT(*size & 0x80);
+ *size &= 0xff;
+ for (i = 0; i < 3; i++) {
+ ptr++;
+ size_t byte = (uint8_t)ptr[-1];
+ *size += (byte - 1) << (7 + 7 * i);
+ if (UPB_LIKELY((byte & 0x80) == 0)) return ptr;
+ }
+ ptr++;
+ size_t byte = (uint8_t)ptr[-1];
+ // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected
+ // for a 32 bit varint.
+ if (UPB_UNLIKELY(byte >= 8)) return NULL;
+ *size += (byte - 1) << 28;
+ return ptr;
+}
+
+UPB_FORCEINLINE
+static bool fastdecode_boundscheck(const char *ptr, size_t len,
+ const char *end) {
+ uintptr_t uptr = (uintptr_t)ptr;
+ uintptr_t uend = (uintptr_t)end + 16;
+ uintptr_t res = uptr + len;
+ return res < uptr || res > uend;
+}
+
+UPB_FORCEINLINE
+static bool fastdecode_boundscheck2(const char *ptr, size_t len,
+ const char *end) {
+ // This is one extra branch compared to the more normal:
+ // return (size_t)(end - ptr) < size;
+ // However it is one less computation if we are just about to use "ptr + len":
+ // https://godbolt.org/z/35YGPz
+ // In microbenchmarks this shows an overall 4% improvement.
+ uintptr_t uptr = (uintptr_t)ptr;
+ uintptr_t uend = (uintptr_t)end;
+ uintptr_t res = uptr + len;
+ return res < uptr || res > uend;
+}
+
+typedef const char *fastdecode_delimfunc(upb_decstate *d, const char *ptr,
+ void *ctx);
+
+UPB_FORCEINLINE
+static const char *fastdecode_delimited(upb_decstate *d, const char *ptr,
+ fastdecode_delimfunc *func, void *ctx) {
+ ptr++;
+ int len = (int8_t)ptr[-1];
+ if (fastdecode_boundscheck2(ptr, len, d->limit_ptr)) {
+ // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer.
+ // If it exceeds the buffer limit, limit/limit_ptr will change during
+ // sub-message parsing, so we need to preserve delta, not limit.
+ if (UPB_UNLIKELY(len & 0x80)) {
+ // Size varint >1 byte (length >= 128).
+ ptr = fastdecode_longsize(ptr, &len);
+ if (!ptr) {
+ // Corrupt wire format: size exceeded INT_MAX.
+ return NULL;
+ }
+ }
+ if (ptr - d->end + (int)len > d->limit) {
+ // Corrupt wire format: invalid limit.
+ return NULL;
+ }
+ int delta = decode_pushlimit(d, ptr, len);
+ ptr = func(d, ptr, ctx);
+ decode_poplimit(d, ptr, delta);
+ } else {
+ // Fast case: Sub-message is <128 bytes and fits in the current buffer.
+ // This means we can preserve limit/limit_ptr verbatim.
+ const char *saved_limit_ptr = d->limit_ptr;
+ int saved_limit = d->limit;
+ d->limit_ptr = ptr + len;
+ d->limit = d->limit_ptr - d->end;
+ UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit));
+ ptr = func(d, ptr, ctx);
+ d->limit_ptr = saved_limit_ptr;
+ d->limit = saved_limit;
+ UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit));
+ }
+ return ptr;
+}
+
+/* singular, oneof, repeated field handling ***********************************/
+
+typedef struct {
+ upb_array *arr;
+ void *end;
+} fastdecode_arr;
+
+typedef enum {
+ FD_NEXT_ATLIMIT,
+ FD_NEXT_SAMEFIELD,
+ FD_NEXT_OTHERFIELD
+} fastdecode_next;
+
+typedef struct {
+ void *dst;
+ fastdecode_next next;
+ uint32_t tag;
+} fastdecode_nextret;
+
+UPB_FORCEINLINE
+static void *fastdecode_resizearr(upb_decstate *d, void *dst,
+ fastdecode_arr *farr, int valbytes) {
+ if (UPB_UNLIKELY(dst == farr->end)) {
+ size_t old_size = farr->arr->size;
+ size_t old_bytes = old_size * valbytes;
+ size_t new_size = old_size * 2;
+ size_t new_bytes = new_size * valbytes;
+ char *old_ptr = _upb_array_ptr(farr->arr);
+ char *new_ptr = upb_arena_realloc(&d->arena, old_ptr, old_bytes, new_bytes);
+ uint8_t elem_size_lg2 = __builtin_ctz(valbytes);
+ farr->arr->size = new_size;
+ farr->arr->data = _upb_array_tagptr(new_ptr, elem_size_lg2);
+ dst = (void*)(new_ptr + (old_size * valbytes));
+ farr->end = (void*)(new_ptr + (new_size * valbytes));
+ }
+ return dst;
+}
+
+UPB_FORCEINLINE
+static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
+ if (tagbytes == 1) {
+ return (uint8_t)tag == (uint8_t)data;
+ } else {
+ return (uint16_t)tag == (uint16_t)data;
+ }
+}
+
+UPB_FORCEINLINE
+static void fastdecode_commitarr(void *dst, fastdecode_arr *farr,
+ int valbytes) {
+ farr->arr->len =
+ (size_t)((char *)dst - (char *)_upb_array_ptr(farr->arr)) / valbytes;
+}
+
+UPB_FORCEINLINE
+static fastdecode_nextret fastdecode_nextrepeated(upb_decstate *d, void *dst,
+ const char **ptr,
+ fastdecode_arr *farr,
+ uint64_t data, int tagbytes,
+ int valbytes) {
+ fastdecode_nextret ret;
+ dst = (char *)dst + valbytes;
+
+ if (UPB_LIKELY(!decode_isdone(d, ptr))) {
+ ret.tag = fastdecode_loadtag(*ptr);
+ if (fastdecode_tagmatch(ret.tag, data, tagbytes)) {
+ ret.next = FD_NEXT_SAMEFIELD;
+ } else {
+ fastdecode_commitarr(dst, farr, valbytes);
+ ret.next = FD_NEXT_OTHERFIELD;
+ }
+ } else {
+ fastdecode_commitarr(dst, farr, valbytes);
+ ret.next = FD_NEXT_ATLIMIT;
+ }
+
+ ret.dst = dst;
+ return ret;
+}
+
+UPB_FORCEINLINE
+static void *fastdecode_fieldmem(upb_msg *msg, uint64_t data) {
+ size_t ofs = data >> 48;
+ return (char *)msg + ofs;
+}
+
+UPB_FORCEINLINE
+static void *fastdecode_getfield(upb_decstate *d, const char *ptr, upb_msg *msg,
+ uint64_t *data, uint64_t *hasbits,
+ fastdecode_arr *farr, int valbytes,
+ upb_card card) {
+ switch (card) {
+ case CARD_s: {
+ uint8_t hasbit_index = *data >> 24;
+ // Set hasbit and return pointer to scalar field.
+ *hasbits |= 1ull << hasbit_index;
+ return fastdecode_fieldmem(msg, *data);
+ }
+ case CARD_o: {
+ uint16_t case_ofs = *data >> 32;
+ uint32_t *oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t);
+ uint8_t field_number = *data >> 24;
+ *oneof_case = field_number;
+ return fastdecode_fieldmem(msg, *data);
+ }
+ case CARD_r: {
+ // Get pointer to upb_array and allocate/expand if necessary.
+ uint8_t elem_size_lg2 = __builtin_ctz(valbytes);
+ upb_array **arr_p = fastdecode_fieldmem(msg, *data);
+ char *begin;
+ *(uint32_t*)msg |= *hasbits;
+ *hasbits = 0;
+ if (UPB_LIKELY(!*arr_p)) {
+ farr->arr = _upb_array_new(&d->arena, 8, elem_size_lg2);
+ *arr_p = farr->arr;
+ } else {
+ farr->arr = *arr_p;
+ }
+ begin = _upb_array_ptr(farr->arr);
+ farr->end = begin + (farr->arr->size * valbytes);
+ *data = fastdecode_loadtag(ptr);
+ return begin + (farr->arr->len * valbytes);
+ }
+ default:
+ UPB_UNREACHABLE();
+ }
+}
+
+UPB_FORCEINLINE
+static bool fastdecode_flippacked(uint64_t *data, int tagbytes) {
+ *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype.
+ return fastdecode_checktag(*data, tagbytes);
+}
+
+/* varint fields **************************************************************/
+
+UPB_FORCEINLINE
+static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
+ if (valbytes == 1) {
+ return val != 0;
+ } else if (zigzag) {
+ if (valbytes == 4) {
+ uint32_t n = val;
+ return (n >> 1) ^ -(int32_t)(n & 1);
+ } else if (valbytes == 8) {
+ return (val >> 1) ^ -(int64_t)(val & 1);
+ }
+ UPB_UNREACHABLE();
+ }
+ return val;
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_varint64(const char *ptr, uint64_t *val) {
+ ptr++;
+ *val = (uint8_t)ptr[-1];
+ if (UPB_UNLIKELY(*val & 0x80)) {
+ int i;
+ for (i = 0; i < 8; i++) {
+ ptr++;
+ uint64_t byte = (uint8_t)ptr[-1];
+ *val += (byte - 1) << (7 + 7 * i);
+ if (UPB_LIKELY((byte & 0x80) == 0)) goto done;
+ }
+ ptr++;
+ uint64_t byte = (uint8_t)ptr[-1];
+ if (byte > 1) {
+ return NULL;
+ }
+ *val += (byte - 1) << 63;
+ }
+done:
+ UPB_ASSUME(ptr != NULL);
+ return ptr;
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_unpackedvarint(UPB_PARSE_PARAMS, int tagbytes,
+ int valbytes, upb_card card,
+ bool zigzag,
+ _upb_field_parser *packed) {
+ uint64_t val;
+ void *dst;
+ fastdecode_arr farr;
+
+ if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) {
+ if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) {
+ return packed(UPB_PARSE_ARGS);
+ }
+ RETURN_GENERIC("varint field tag mismatch\n");
+ }
+
+ dst =
+ fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, card);
+ if (card == CARD_r) {
+ if (UPB_UNLIKELY(!dst)) {
+ RETURN_GENERIC("need array resize\n");
+ }
+ }
+
+again:
+ if (card == CARD_r) {
+ dst = fastdecode_resizearr(d, dst, &farr, valbytes);
+ }
+
+ ptr += tagbytes;
+ ptr = fastdecode_varint64(ptr, &val);
+ if (ptr == NULL) return fastdecode_err(d);
+ val = fastdecode_munge(val, valbytes, zigzag);
+ memcpy(dst, &val, valbytes);
+
+ if (card == CARD_r) {
+ fastdecode_nextret ret =
+ fastdecode_nextrepeated(d, dst, &ptr, &farr, data, tagbytes, valbytes);
+ switch (ret.next) {
+ case FD_NEXT_SAMEFIELD:
+ dst = ret.dst;
+ goto again;
+ case FD_NEXT_OTHERFIELD:
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, ret.tag);
+ case FD_NEXT_ATLIMIT:
+ return ptr;
+ }
+ }
+
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+}
+
+typedef struct {
+ uint8_t valbytes;
+ bool zigzag;
+ void *dst;
+ fastdecode_arr farr;
+} fastdecode_varintdata;
+
+UPB_FORCEINLINE
+static const char *fastdecode_topackedvarint(upb_decstate *d, const char *ptr,
+ void *ctx) {
+ fastdecode_varintdata *data = ctx;
+ void *dst = data->dst;
+ uint64_t val;
+
+ while (!decode_isdone(d, &ptr)) {
+ dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes);
+ ptr = fastdecode_varint64(ptr, &val);
+ if (ptr == NULL) return NULL;
+ val = fastdecode_munge(val, data->valbytes, data->zigzag);
+ memcpy(dst, &val, data->valbytes);
+ dst = (char *)dst + data->valbytes;
+ }
+
+ fastdecode_commitarr(dst, &data->farr, data->valbytes);
+ return ptr;
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_packedvarint(UPB_PARSE_PARAMS, int tagbytes,
+ int valbytes, bool zigzag,
+ _upb_field_parser *unpacked) {
+ fastdecode_varintdata ctx = {valbytes, zigzag};
+
+ if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) {
+ if (fastdecode_flippacked(&data, tagbytes)) {
+ return unpacked(UPB_PARSE_ARGS);
+ } else {
+ RETURN_GENERIC("varint field tag mismatch\n");
+ }
+ }
+
+ ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr,
+ valbytes, CARD_r);
+ if (UPB_UNLIKELY(!ctx.dst)) {
+ RETURN_GENERIC("need array resize\n");
+ }
+
+ ptr += tagbytes;
+ ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx);
+
+ if (UPB_UNLIKELY(ptr == NULL)) {
+ return fastdecode_err(d);
+ }
+
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_varint(UPB_PARSE_PARAMS, int tagbytes,
+ int valbytes, upb_card card, bool zigzag,
+ _upb_field_parser *unpacked,
+ _upb_field_parser *packed) {
+ if (card == CARD_p) {
+ return fastdecode_packedvarint(UPB_PARSE_ARGS, tagbytes, valbytes, zigzag,
+ unpacked);
+ } else {
+ return fastdecode_unpackedvarint(UPB_PARSE_ARGS, tagbytes, valbytes, card,
+ zigzag, packed);
+ }
+}
+
+#define z_ZZ true
+#define b_ZZ false
+#define v_ZZ false
+
+/* Generate all combinations:
+ * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */
+
+#define F(card, type, valbytes, tagbytes) \
+ UPB_NOINLINE \
+ const char *upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \
+ return fastdecode_varint(UPB_PARSE_ARGS, tagbytes, valbytes, CARD_##card, \
+ type##_ZZ, \
+ &upb_pr##type##valbytes##_##tagbytes##bt, \
+ &upb_pp##type##valbytes##_##tagbytes##bt); \
+ }
+
+#define TYPES(card, tagbytes) \
+ F(card, b, 1, tagbytes) \
+ F(card, v, 4, tagbytes) \
+ F(card, v, 8, tagbytes) \
+ F(card, z, 4, tagbytes) \
+ F(card, z, 8, tagbytes)
+
+#define TAGBYTES(card) \
+ TYPES(card, 1) \
+ TYPES(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+TAGBYTES(p)
+
+#undef z_ZZ
+#undef b_ZZ
+#undef v_ZZ
+#undef o_ONEOF
+#undef s_ONEOF
+#undef r_ONEOF
+#undef F
+#undef TYPES
+#undef TAGBYTES
+
+
+/* fixed fields ***************************************************************/
+
+UPB_FORCEINLINE
+static const char *fastdecode_unpackedfixed(UPB_PARSE_PARAMS, int tagbytes,
+ int valbytes, upb_card card,
+ _upb_field_parser *packed) {
+ void *dst;
+ fastdecode_arr farr;
+
+ if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) {
+ if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) {
+ return packed(UPB_PARSE_ARGS);
+ }
+ RETURN_GENERIC("fixed field tag mismatch\n");
+ }
+
+ dst =
+ fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, card);
+ if (card == CARD_r) {
+ if (UPB_UNLIKELY(!dst)) {
+ RETURN_GENERIC("couldn't allocate array in arena\n");
+ }
+ }
+
+
+again:
+ if (card == CARD_r) {
+ dst = fastdecode_resizearr(d, dst, &farr, valbytes);
+ }
+
+ ptr += tagbytes;
+ memcpy(dst, ptr, valbytes);
+ ptr += valbytes;
+
+ if (card == CARD_r) {
+ fastdecode_nextret ret =
+ fastdecode_nextrepeated(d, dst, &ptr, &farr, data, tagbytes, valbytes);
+ switch (ret.next) {
+ case FD_NEXT_SAMEFIELD:
+ dst = ret.dst;
+ goto again;
+ case FD_NEXT_OTHERFIELD:
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, ret.tag);
+ case FD_NEXT_ATLIMIT:
+ return ptr;
+ }
+ }
+
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_packedfixed(UPB_PARSE_PARAMS, int tagbytes,
+ int valbytes,
+ _upb_field_parser *unpacked) {
+ if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) {
+ if (fastdecode_flippacked(&data, tagbytes)) {
+ return unpacked(UPB_PARSE_ARGS);
+ } else {
+ RETURN_GENERIC("varint field tag mismatch\n");
+ }
+ }
+
+ ptr += tagbytes;
+ int size = (uint8_t)ptr[0];
+ ptr++;
+ if (size & 0x80) {
+ ptr = fastdecode_longsize(ptr, &size);
+ }
+
+ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr)) ||
+ (size % valbytes) != 0) {
+ return fastdecode_err(d);
+ }
+
+ upb_array **arr_p = fastdecode_fieldmem(msg, data);
+ upb_array *arr = *arr_p;
+ uint8_t elem_size_lg2 = __builtin_ctz(valbytes);
+ int elems = size / valbytes;
+
+ if (UPB_LIKELY(!arr)) {
+ *arr_p = arr = _upb_array_new(&d->arena, elems, elem_size_lg2);
+ if (!arr) {
+ return fastdecode_err(d);
+ }
+ } else {
+ _upb_array_resize(arr, elems, &d->arena);
+ }
+
+ char *dst = _upb_array_ptr(arr);
+ memcpy(dst, ptr, size);
+ arr->len = elems;
+
+ return fastdecode_dispatch(d, ptr + size, msg, table, hasbits);
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_fixed(UPB_PARSE_PARAMS, int tagbytes,
+ int valbytes, upb_card card,
+ _upb_field_parser *unpacked,
+ _upb_field_parser *packed) {
+ if (card == CARD_p) {
+ return fastdecode_packedfixed(UPB_PARSE_ARGS, tagbytes, valbytes, unpacked);
+ } else {
+ return fastdecode_unpackedfixed(UPB_PARSE_ARGS, tagbytes, valbytes, card,
+ packed);
+ }
+}
+
+/* Generate all combinations:
+ * {s,o,r,p} x {f4,f8} x {1bt,2bt} */
+
+#define F(card, valbytes, tagbytes) \
+ UPB_NOINLINE \
+ const char *upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \
+ return fastdecode_fixed(UPB_PARSE_ARGS, tagbytes, valbytes, CARD_##card, \
+ &upb_ppf##valbytes##_##tagbytes##bt, \
+ &upb_prf##valbytes##_##tagbytes##bt); \
+ }
+
+#define TYPES(card, tagbytes) \
+ F(card, 4, tagbytes) \
+ F(card, 8, tagbytes)
+
+#define TAGBYTES(card) \
+ TYPES(card, 1) \
+ TYPES(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+TAGBYTES(p)
+
+#undef F
+#undef TYPES
+#undef TAGBYTES
+
+/* string fields **************************************************************/
+
+typedef const char *fastdecode_copystr_func(struct upb_decstate *d,
+ const char *ptr, upb_msg *msg,
+ const upb_msglayout *table,
+ uint64_t hasbits, upb_strview *dst);
+
+UPB_NOINLINE
+static const char *fastdecode_verifyutf8(upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table,
+ uint64_t hasbits, upb_strview *dst) {
+ if (!decode_verifyutf8_inl(dst->data, dst->size)) {
+ return fastdecode_err(d);
+ }
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_longstring(struct upb_decstate *d,
+ const char *ptr, upb_msg *msg,
+ intptr_t table, uint64_t hasbits,
+ upb_strview *dst,
+ bool validate_utf8) {
+ int size = (uint8_t)ptr[0]; // Could plumb through hasbits.
+ ptr++;
+ if (size & 0x80) {
+ ptr = fastdecode_longsize(ptr, &size);
+ }
+
+ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr))) {
+ dst->size = 0;
+ return fastdecode_err(d);
+ }
+
+ if (d->alias) {
+ dst->data = ptr;
+ dst->size = size;
+ } else {
+ char *data = upb_arena_malloc(&d->arena, size);
+ if (!data) {
+ return fastdecode_err(d);
+ }
+ memcpy(data, ptr, size);
+ dst->data = data;
+ dst->size = size;
+ }
+
+ if (validate_utf8) {
+ return fastdecode_verifyutf8(d, ptr + size, msg, table, hasbits, dst);
+ } else {
+ return fastdecode_dispatch(d, ptr + size, msg, table, hasbits);
+ }
+}
+
+UPB_NOINLINE
+static const char *fastdecode_longstring_utf8(struct upb_decstate *d,
+ const char *ptr, upb_msg *msg,
+ intptr_t table, uint64_t hasbits,
+ upb_strview *dst) {
+ return fastdecode_longstring(d, ptr, msg, table, hasbits, dst, true);
+}
+
+UPB_NOINLINE
+static const char *fastdecode_longstring_noutf8(struct upb_decstate *d,
+ const char *ptr, upb_msg *msg,
+ intptr_t table,
+ uint64_t hasbits,
+ upb_strview *dst) {
+ return fastdecode_longstring(d, ptr, msg, table, hasbits, dst, false);
+}
+
+UPB_FORCEINLINE
+static void fastdecode_docopy(upb_decstate *d, const char *ptr, uint32_t size,
+ int copy, char *data, upb_strview *dst) {
+ d->arena.head.ptr += copy;
+ dst->data = data;
+ UPB_UNPOISON_MEMORY_REGION(data, copy);
+ memcpy(data, ptr, copy);
+ UPB_POISON_MEMORY_REGION(data + size, copy - size);
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_copystring(UPB_PARSE_PARAMS, int tagbytes,
+ upb_card card, bool validate_utf8) {
+ upb_strview *dst;
+ fastdecode_arr farr;
+ int64_t size;
+ size_t arena_has;
+ size_t common_has;
+ char *buf;
+
+ UPB_ASSERT(!d->alias);
+ UPB_ASSERT(fastdecode_checktag(data, tagbytes));
+
+ dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr,
+ sizeof(upb_strview), card);
+
+again:
+ if (card == CARD_r) {
+ dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_strview));
+ }
+
+ size = (uint8_t)ptr[tagbytes];
+ ptr += tagbytes + 1;
+ dst->size = size;
+
+ buf = d->arena.head.ptr;
+ arena_has = _upb_arenahas(&d->arena);
+ common_has = UPB_MIN(arena_has, (d->end - ptr) + 16);
+
+ if (UPB_LIKELY(size <= 15 - tagbytes)) {
+ if (arena_has < 16) goto longstr;
+ d->arena.head.ptr += 16;
+ memcpy(buf, ptr - tagbytes - 1, 16);
+ dst->data = buf + tagbytes + 1;
+ } else if (UPB_LIKELY(size <= 32)) {
+ if (UPB_UNLIKELY(common_has < 32)) goto longstr;
+ fastdecode_docopy(d, ptr, size, 32, buf, dst);
+ } else if (UPB_LIKELY(size <= 64)) {
+ if (UPB_UNLIKELY(common_has < 64)) goto longstr;
+ fastdecode_docopy(d, ptr, size, 64, buf, dst);
+ } else if (UPB_LIKELY(size <= 128)) {
+ if (UPB_UNLIKELY(common_has < 128)) goto longstr;
+ fastdecode_docopy(d, ptr, size, 128, buf, dst);
+ } else {
+ goto longstr;
+ }
+
+ ptr += size;
+
+ if (card == CARD_r) {
+ if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) {
+ return fastdecode_err(d);
+ }
+ fastdecode_nextret ret = fastdecode_nextrepeated(
+ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_strview));
+ switch (ret.next) {
+ case FD_NEXT_SAMEFIELD:
+ dst = ret.dst;
+ goto again;
+ case FD_NEXT_OTHERFIELD:
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, ret.tag);
+ case FD_NEXT_ATLIMIT:
+ return ptr;
+ }
+ }
+
+ if (card != CARD_r && validate_utf8) {
+ return fastdecode_verifyutf8(d, ptr, msg, table, hasbits, dst);
+ }
+
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+
+longstr:
+ ptr--;
+ if (validate_utf8) {
+ return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, dst);
+ } else {
+ return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, dst);
+ }
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_string(UPB_PARSE_PARAMS, int tagbytes,
+ upb_card card, _upb_field_parser *copyfunc,
+ bool validate_utf8) {
+ upb_strview *dst;
+ fastdecode_arr farr;
+ int64_t size;
+
+ if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) {
+ RETURN_GENERIC("string field tag mismatch\n");
+ }
+
+ if (UPB_UNLIKELY(!d->alias)) {
+ return copyfunc(UPB_PARSE_ARGS);
+ }
+
+ dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr,
+ sizeof(upb_strview), card);
+
+again:
+ if (card == CARD_r) {
+ dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_strview));
+ }
+
+ size = (int8_t)ptr[tagbytes];
+ ptr += tagbytes + 1;
+ dst->data = ptr;
+ dst->size = size;
+
+ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->end))) {
+ ptr--;
+ if (validate_utf8) {
+ return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, dst);
+ } else {
+ return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, dst);
+ }
+ }
+
+ ptr += size;
+
+ if (card == CARD_r) {
+ if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) {
+ return fastdecode_err(d);
+ }
+ fastdecode_nextret ret = fastdecode_nextrepeated(
+ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_strview));
+ switch (ret.next) {
+ case FD_NEXT_SAMEFIELD:
+ dst = ret.dst;
+ if (UPB_UNLIKELY(!d->alias)) {
+ // Buffer flipped and we can't alias any more. Bounce to copyfunc(),
+ // but via dispatch since we need to reload table data also.
+ fastdecode_commitarr(dst, &farr, sizeof(upb_strview));
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, ret.tag);
+ }
+ goto again;
+ case FD_NEXT_OTHERFIELD:
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, ret.tag);
+ case FD_NEXT_ATLIMIT:
+ return ptr;
+ }
+ }
+
+ if (card != CARD_r && validate_utf8) {
+ return fastdecode_verifyutf8(d, ptr, msg, table, hasbits, dst);
+ }
+
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+}
+
+/* Generate all combinations:
+ * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */
+
+#define s_VALIDATE true
+#define b_VALIDATE false
+
+#define F(card, tagbytes, type) \
+ UPB_NOINLINE \
+ const char *upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \
+ return fastdecode_copystring(UPB_PARSE_ARGS, tagbytes, CARD_##card, \
+ type##_VALIDATE); \
+ } \
+ const char *upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \
+ return fastdecode_string(UPB_PARSE_ARGS, tagbytes, CARD_##card, \
+ &upb_c##card##type##_##tagbytes##bt, \
+ type##_VALIDATE); \
+ }
+
+#define UTF8(card, tagbytes) \
+ F(card, tagbytes, s) \
+ F(card, tagbytes, b)
+
+#define TAGBYTES(card) \
+ UTF8(card, 1) \
+ UTF8(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+
+#undef s_VALIDATE
+#undef b_VALIDATE
+#undef F
+#undef TAGBYTES
+
+/* message fields *************************************************************/
+
+UPB_INLINE
+upb_msg *decode_newmsg_ceil(upb_decstate *d, const upb_msglayout *l,
+ int msg_ceil_bytes) {
+ size_t size = l->size + sizeof(upb_msg_internal);
+ char *msg_data;
+ if (UPB_LIKELY(msg_ceil_bytes > 0 &&
+ _upb_arenahas(&d->arena) >= msg_ceil_bytes)) {
+ UPB_ASSERT(size <= (size_t)msg_ceil_bytes);
+ msg_data = d->arena.head.ptr;
+ d->arena.head.ptr += size;
+ UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes);
+ memset(msg_data, 0, msg_ceil_bytes);
+ UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size);
+ } else {
+ msg_data = (char*)upb_arena_malloc(&d->arena, size);
+ memset(msg_data, 0, size);
+ }
+ return msg_data + sizeof(upb_msg_internal);
+}
+
+typedef struct {
+ intptr_t table;
+ upb_msg *msg;
+} fastdecode_submsgdata;
+
+UPB_FORCEINLINE
+static const char *fastdecode_tosubmsg(upb_decstate *d, const char *ptr,
+ void *ctx) {
+ fastdecode_submsgdata *submsg = ctx;
+ ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0);
+ UPB_ASSUME(ptr != NULL);
+ return ptr;
+}
+
+UPB_FORCEINLINE
+static const char *fastdecode_submsg(UPB_PARSE_PARAMS, int tagbytes,
+ int msg_ceil_bytes, upb_card card) {
+
+ if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) {
+ RETURN_GENERIC("submessage field tag mismatch\n");
+ }
+
+ if (--d->depth == 0) return fastdecode_err(d);
+
+ upb_msg **dst;
+ uint32_t submsg_idx = (data >> 16) & 0xff;
+ const upb_msglayout *tablep = decode_totablep(table);
+ const upb_msglayout *subtablep = tablep->submsgs[submsg_idx];
+ fastdecode_submsgdata submsg = {decode_totable(subtablep)};
+ fastdecode_arr farr;
+
+ if (subtablep->table_mask == (uint8_t)-1) {
+ RETURN_GENERIC("submessage doesn't have fast tables.");
+ }
+
+ dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr,
+ sizeof(upb_msg *), card);
+
+ if (card == CARD_s) {
+ *(uint32_t*)msg |= hasbits;
+ hasbits = 0;
+ }
+
+again:
+ if (card == CARD_r) {
+ dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_msg*));
+ }
+
+ submsg.msg = *dst;
+
+ if (card == CARD_r || UPB_LIKELY(!submsg.msg)) {
+ *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes);
+ }
+
+ ptr += tagbytes;
+ ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg);
+
+ if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) {
+ return fastdecode_err(d);
+ }
+
+ if (card == CARD_r) {
+ fastdecode_nextret ret = fastdecode_nextrepeated(
+ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_msg *));
+ switch (ret.next) {
+ case FD_NEXT_SAMEFIELD:
+ dst = ret.dst;
+ goto again;
+ case FD_NEXT_OTHERFIELD:
+ d->depth++;
+ return fastdecode_tagdispatch(d, ptr, msg, table, hasbits, ret.tag);
+ case FD_NEXT_ATLIMIT:
+ d->depth++;
+ return ptr;
+ }
+ }
+
+ d->depth++;
+ return fastdecode_dispatch(d, ptr, msg, table, hasbits);
+}
+
+#define F(card, tagbytes, size_ceil, ceil_arg) \
+ const char *upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \
+ UPB_PARSE_PARAMS) { \
+ return fastdecode_submsg(UPB_PARSE_ARGS, tagbytes, ceil_arg, CARD_##card); \
+ }
+
+#define SIZES(card, tagbytes) \
+ F(card, tagbytes, 64, 64) \
+ F(card, tagbytes, 128, 128) \
+ F(card, tagbytes, 192, 192) \
+ F(card, tagbytes, 256, 256) \
+ F(card, tagbytes, max, -1)
+
+#define TAGBYTES(card) \
+ SIZES(card, 1) \
+ SIZES(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+
+#undef TAGBYTES
+#undef SIZES
+#undef F
+
+#endif /* UPB_FASTTABLE */
diff --git a/upb/decode_fast.h b/upb/decode_fast.h
new file mode 100644
index 0000000..6d56d12
--- /dev/null
+++ b/upb/decode_fast.h
@@ -0,0 +1,126 @@
+// These are the specialized field parser functions for the fast parser.
+// Generated tables will refer to these by name.
+//
+// The function names are encoded with names like:
+//
+// // 123 4
+// upb_pss_1bt(); // Parse singular string, 1 byte tag.
+//
+// In position 1:
+// - 'p' for parse, most function use this
+// - 'c' for copy, for when we are copying strings instead of aliasing
+//
+// In position 2 (cardinality):
+// - 's' for singular, with or without hasbit
+// - 'o' for oneof
+// - 'r' for non-packed repeated
+// - 'p' for packed repeated
+//
+// In position 3 (type):
+// - 'b1' for bool
+// - 'v4' for 4-byte varint
+// - 'v8' for 8-byte varint
+// - 'z4' for zig-zag-encoded 4-byte varint
+// - 'z8' for zig-zag-encoded 8-byte varint
+// - 'f4' for 4-byte fixed
+// - 'f8' for 8-byte fixed
+// - 'm' for sub-message
+// - 's' for string (validate UTF-8)
+// - 'b' for bytes
+//
+// In position 4 (tag length):
+// - '1' for one-byte tags (field numbers 1-15)
+// - '2' for two-byte tags (field numbers 16-2048)
+
+#ifndef UPB_DECODE_FAST_H_
+#define UPB_DECODE_FAST_H_
+
+#include "upb/msg.h"
+
+struct upb_decstate;
+
+// The fallback, generic parsing function that can handle any field type.
+// This just uses the regular (non-fast) parser to parse a single field.
+const char *fastdecode_generic(struct upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table, uint64_t hasbits,
+ uint64_t data);
+
+#define UPB_PARSE_PARAMS \
+ struct upb_decstate *d, const char *ptr, upb_msg *msg, intptr_t table, \
+ uint64_t hasbits, uint64_t data
+
+/* primitive fields ***********************************************************/
+
+#define F(card, type, valbytes, tagbytes) \
+ const char *upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS);
+
+#define TYPES(card, tagbytes) \
+ F(card, b, 1, tagbytes) \
+ F(card, v, 4, tagbytes) \
+ F(card, v, 8, tagbytes) \
+ F(card, z, 4, tagbytes) \
+ F(card, z, 8, tagbytes) \
+ F(card, f, 4, tagbytes) \
+ F(card, f, 8, tagbytes)
+
+#define TAGBYTES(card) \
+ TYPES(card, 1) \
+ TYPES(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+TAGBYTES(p)
+
+#undef F
+#undef TYPES
+#undef TAGBYTES
+
+/* string fields **************************************************************/
+
+#define F(card, tagbytes, type) \
+ const char *upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \
+ const char *upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS);
+
+#define UTF8(card, tagbytes) \
+ F(card, tagbytes, s) \
+ F(card, tagbytes, b)
+
+#define TAGBYTES(card) \
+ UTF8(card, 1) \
+ UTF8(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+
+#undef F
+#undef TAGBYTES
+
+/* sub-message fields *********************************************************/
+
+#define F(card, tagbytes, size_ceil, ceil_arg) \
+ const char *upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS);
+
+#define SIZES(card, tagbytes) \
+ F(card, tagbytes, 64, 64) \
+ F(card, tagbytes, 128, 128) \
+ F(card, tagbytes, 192, 192) \
+ F(card, tagbytes, 256, 256) \
+ F(card, tagbytes, max, -1)
+
+#define TAGBYTES(card) \
+ SIZES(card, 1) \
+ SIZES(card, 2)
+
+TAGBYTES(s)
+TAGBYTES(o)
+TAGBYTES(r)
+
+#undef TAGBYTES
+#undef SIZES
+#undef F
+
+#undef UPB_PARSE_PARAMS
+
+#endif /* UPB_DECODE_FAST_H_ */
diff --git a/upb/def.c b/upb/def.c
index 0f17f1b..19b30fe 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -1031,7 +1031,7 @@
const upb_msglayout **submsgs;
upb_msglayout_field *fields;
- memset(l, 0, sizeof(*l));
+ memset(l, 0, sizeof(*l) + sizeof(_upb_fasttable_entry));
fields = symtab_alloc(ctx, upb_msgdef_numfields(m) * sizeof(*fields));
submsgs = symtab_alloc(ctx, submsg_count * sizeof(*submsgs));
@@ -1039,6 +1039,12 @@
l->field_count = upb_msgdef_numfields(m);
l->fields = fields;
l->submsgs = submsgs;
+ l->table_mask = 0;
+
+ /* TODO(haberman): initialize fast tables so that reflection-based parsing
+ * can get the same speeds as linked-in types. */
+ l->fasttable[0].field_parser = &fastdecode_generic;
+ l->fasttable[0].field_data = 0;
if (upb_msgdef_mapentry(m)) {
/* TODO(haberman): refactor this method so this special case is more
@@ -1801,7 +1807,8 @@
ctx->layouts++;
} else {
/* Allocate now (to allow cross-linking), populate later. */
- m->layout = symtab_alloc(ctx, sizeof(*m->layout));
+ m->layout = symtab_alloc(
+ ctx, sizeof(*m->layout) + sizeof(_upb_fasttable_entry));
}
m->oneof_count = 0;
diff --git a/upb/msg.h b/upb/msg.h
index 0638182..36c57b3 100644
--- a/upb/msg.h
+++ b/upb/msg.h
@@ -46,6 +46,18 @@
uint8_t label; /* google.protobuf.Label or _UPB_LABEL_* above. */
} upb_msglayout_field;
+struct upb_decstate;
+struct upb_msglayout;
+
+typedef const char *_upb_field_parser(struct upb_decstate *d, const char *ptr,
+ upb_msg *msg, intptr_t table,
+ uint64_t hasbits, uint64_t data);
+
+typedef struct {
+ uint64_t field_data;
+ _upb_field_parser *field_parser;
+} _upb_fasttable_entry;
+
typedef struct upb_msglayout {
const struct upb_msglayout *const* submsgs;
const upb_msglayout_field *fields;
@@ -54,6 +66,10 @@
uint16_t size;
uint16_t field_count;
bool extendable;
+ uint8_t table_mask;
+ /* To constant-initialize the tables of variable length, we need a flexible
+ * array member, and we need to compile in C99 mode. */
+ _upb_fasttable_entry fasttable[];
} upb_msglayout;
/** upb_msg *******************************************************************/
@@ -198,6 +214,11 @@
return (void*)(arr->data & ~(uintptr_t)7);
}
+UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) {
+ UPB_ASSERT(elem_size_lg2 <= 4);
+ return (uintptr_t)ptr | elem_size_lg2;
+}
+
UPB_INLINE void *_upb_array_ptr(upb_array *arr) {
return (void*)_upb_array_constptr(arr);
}
diff --git a/upb/port_def.inc b/upb/port_def.inc
index 0d25c90..f1ed464 100644
--- a/upb/port_def.inc
+++ b/upb/port_def.inc
@@ -125,6 +125,43 @@
#define UPB_UNREACHABLE() do { assert(0); } while(0)
#endif
+/* Configure whether fasttable is switched on or not. *************************/
+
+#if defined(__x86_64__) && defined(__GNUC__)
+#define UPB_FASTTABLE_SUPPORTED 1
+#else
+#define UPB_FASTTABLE_SUPPORTED 0
+#endif
+
+/* define UPB_ENABLE_FASTTABLE to force fast table support.
+ * This is useful when we want to ensure we are really getting fasttable,
+ * for example for testing or benchmarking. */
+#if defined(UPB_ENABLE_FASTTABLE)
+#if !UPB_FASTTABLE_SUPPORTED
+#error fasttable is x86-64 + Clang/GCC only
+#endif
+#define UPB_FASTTABLE 1
+/* Define UPB_TRY_ENABLE_FASTTABLE to use fasttable if possible.
+ * This is useful for releasing code that might be used on multiple platforms,
+ * for example the PHP or Ruby C extensions. */
+#elif defined(UPB_TRY_ENABLE_FASTTABLE)
+#define UPB_FASTTABLE UPB_FASTTABLE_SUPPORTED
+#else
+#define UPB_FASTTABLE 0
+#endif
+
+/* UPB_FASTTABLE_INIT() allows protos compiled for fasttable to gracefully
+ * degrade to non-fasttable if we are using UPB_TRY_ENABLE_FASTTABLE. */
+#if !UPB_FASTTABLE && defined(UPB_TRY_ENABLE_FASTTABLE)
+#define UPB_FASTTABLE_INIT(...)
+#else
+#define UPB_FASTTABLE_INIT(...) __VA_ARGS__
+#endif
+
+#undef UPB_FASTTABLE_SUPPORTED
+
+/* ASAN poisoning (for arena) *************************************************/
+
#if defined(__SANITIZE_ADDRESS__)
#define UPB_ASAN 1
#ifdef __cplusplus
diff --git a/upb/upb.c b/upb/upb.c
index 15dffe2..8e6ad77 100644
--- a/upb/upb.c
+++ b/upb/upb.c
@@ -129,7 +129,7 @@
void *_upb_arena_slowmalloc(upb_arena *a, size_t size) {
if (!upb_arena_allocblock(a, size)) return NULL; /* Out of memory. */
- UPB_ASSERT(_upb_arenahas(a, size));
+ UPB_ASSERT(_upb_arenahas(a) >= size);
return upb_arena_malloc(a, size);
}
@@ -224,9 +224,9 @@
bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func) {
cleanup_ent *ent;
- if (!a->cleanups || !_upb_arenahas(a, sizeof(cleanup_ent))) {
+ if (!a->cleanups || _upb_arenahas(a) < sizeof(cleanup_ent)) {
if (!upb_arena_allocblock(a, 128)) return false; /* Out of memory. */
- UPB_ASSERT(_upb_arenahas(a, sizeof(cleanup_ent)));
+ UPB_ASSERT(_upb_arenahas(a) >= sizeof(cleanup_ent));
}
a->head.end -= sizeof(cleanup_ent);
diff --git a/upb/upb.h b/upb/upb.h
index 055f9c1..7e7309d 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -161,9 +161,9 @@
UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
-UPB_INLINE bool _upb_arenahas(upb_arena *a, size_t size) {
+UPB_INLINE size_t _upb_arenahas(upb_arena *a) {
_upb_arena_head *h = (_upb_arena_head*)a;
- return (size_t)(h->end - h->ptr) >= size;
+ return (size_t)(h->end - h->ptr);
}
UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) {
@@ -171,7 +171,7 @@
void* ret;
size = UPB_ALIGN_MALLOC(size);
- if (UPB_UNLIKELY(!_upb_arenahas(a, size))) {
+ if (UPB_UNLIKELY(_upb_arenahas(a) < size)) {
return _upb_arena_slowmalloc(a, size);
}
@@ -182,7 +182,7 @@
#if UPB_ASAN
{
size_t guard_size = 32;
- if (_upb_arenahas(a, guard_size)) {
+ if (_upb_arenahas(a) >= guard_size) {
h->ptr += guard_size;
} else {
h->ptr = h->end;
diff --git a/upbc/generator.cc b/upbc/generator.cc
index b259948..f4d1bb9 100644
--- a/upbc/generator.cc
+++ b/upbc/generator.cc
@@ -1,6 +1,9 @@
+#include "upbc/generator.h"
+
#include <memory>
+#include "absl/base/attributes.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_replace.h"
@@ -9,8 +12,7 @@
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/zero_copy_stream.h"
-
-#include "upbc/generator.h"
+#include "google/protobuf/wire_format.h"
#include "upbc/message_layout.h"
namespace protoc = ::google::protobuf::compiler;
@@ -140,16 +142,16 @@
std::vector<const protobuf::FieldDescriptor*> FieldNumberOrder(
const protobuf::Descriptor* message) {
- std::vector<const protobuf::FieldDescriptor*> messages;
+ std::vector<const protobuf::FieldDescriptor*> fields;
for (int i = 0; i < message->field_count(); i++) {
- messages.push_back(message->field(i));
+ fields.push_back(message->field(i));
}
- std::sort(messages.begin(), messages.end(),
+ std::sort(fields.begin(), fields.end(),
[](const protobuf::FieldDescriptor* a,
const protobuf::FieldDescriptor* b) {
return a->number() < b->number();
});
- return messages;
+ return fields;
}
std::vector<const protobuf::FieldDescriptor*> SortedSubmessages(
@@ -598,6 +600,7 @@
"#define $0_UPB_H_\n\n"
"#include \"upb/msg.h\"\n"
"#include \"upb/decode.h\"\n"
+ "#include \"upb/decode_fast.h\"\n"
"#include \"upb/encode.h\"\n\n",
ToPreproc(file->name()));
@@ -735,7 +738,200 @@
absl::flat_hash_map<const protobuf::Descriptor*, int> indexes_;
};
-void WriteSource(const protobuf::FileDescriptor* file, Output& output) {
+typedef std::pair<std::string, uint64_t> TableEntry;
+
+uint64_t GetEncodedTag(const protobuf::FieldDescriptor* field) {
+ protobuf::internal::WireFormatLite::WireType wire_type =
+ protobuf::internal::WireFormat::WireTypeForField(field);
+ uint32_t unencoded_tag =
+ protobuf::internal::WireFormatLite::MakeTag(field->number(), wire_type);
+ uint8_t tag_bytes[10] = {0};
+ protobuf::io::CodedOutputStream::WriteVarint32ToArray(unencoded_tag,
+ tag_bytes);
+ uint64_t encoded_tag = 0;
+ memcpy(&encoded_tag, tag_bytes, sizeof(encoded_tag));
+ // TODO: byte-swap for big endian.
+ return encoded_tag;
+}
+
+int GetTableSlot(const protobuf::FieldDescriptor* field) {
+ uint64_t tag = GetEncodedTag(field);
+ if (tag > 0x7fff) {
+ // Tag must fit within a two-byte varint.
+ return -1;
+ }
+ return (tag & 0xf8) >> 3;
+}
+
+bool TryFillTableEntry(const protobuf::Descriptor* message,
+ const MessageLayout& layout,
+ const protobuf::FieldDescriptor* field,
+ TableEntry& ent) {
+ std::string type = "";
+ std::string cardinality = "";
+ switch (field->type()) {
+ case protobuf::FieldDescriptor::TYPE_BOOL:
+ type = "b1";
+ break;
+ case protobuf::FieldDescriptor::TYPE_INT32:
+ case protobuf::FieldDescriptor::TYPE_ENUM:
+ case protobuf::FieldDescriptor::TYPE_UINT32:
+ type = "v4";
+ break;
+ case protobuf::FieldDescriptor::TYPE_INT64:
+ case protobuf::FieldDescriptor::TYPE_UINT64:
+ type = "v8";
+ break;
+ case protobuf::FieldDescriptor::TYPE_FIXED32:
+ case protobuf::FieldDescriptor::TYPE_SFIXED32:
+ case protobuf::FieldDescriptor::TYPE_FLOAT:
+ type = "f4";
+ break;
+ case protobuf::FieldDescriptor::TYPE_FIXED64:
+ case protobuf::FieldDescriptor::TYPE_SFIXED64:
+ case protobuf::FieldDescriptor::TYPE_DOUBLE:
+ type = "f8";
+ break;
+ case protobuf::FieldDescriptor::TYPE_SINT32:
+ type = "z4";
+ break;
+ case protobuf::FieldDescriptor::TYPE_SINT64:
+ type = "z8";
+ break;
+ case protobuf::FieldDescriptor::TYPE_STRING:
+ if (field->file()->syntax() == protobuf::FileDescriptor::SYNTAX_PROTO3) {
+ // Only proto3 validates UTF-8.
+ type = "s";
+ break;
+ }
+ ABSL_FALLTHROUGH_INTENDED;
+ case protobuf::FieldDescriptor::TYPE_BYTES:
+ type = "b";
+ break;
+ case protobuf::FieldDescriptor::TYPE_MESSAGE:
+ if (field->is_map()) {
+ return false; // Not supported yet (ever?).
+ }
+ type = "m";
+ break;
+ default:
+ return false; // Not supported yet.
+ }
+
+ switch (field->label()) {
+ case protobuf::FieldDescriptor::LABEL_REPEATED:
+ if (field->is_packed()) {
+ cardinality = "p";
+ } else {
+ cardinality = "r";
+ }
+ break;
+ case protobuf::FieldDescriptor::LABEL_OPTIONAL:
+ case protobuf::FieldDescriptor::LABEL_REQUIRED:
+ if (field->real_containing_oneof()) {
+ cardinality = "o";
+ } else {
+ cardinality = "s";
+ }
+ break;
+ }
+
+ uint64_t expected_tag = GetEncodedTag(field);
+ MessageLayout::Size offset = layout.GetFieldOffset(field);
+
+ // Data is:
+ //
+ // 48 32 16 0
+ // |--------|--------|--------|--------|--------|--------|--------|--------|
+ // | offset (16) |case offset (16) |presence| submsg | exp. tag (16) |
+ // |--------|--------|--------|--------|--------|--------|--------|--------|
+ //
+ // - |presence| is either hasbit index or field number for oneofs.
+
+ uint64_t data = offset.size64 << 48 | expected_tag;
+
+ if (field->is_repeated()) {
+ // No hasbit/oneof-related fields.
+ } if (field->real_containing_oneof()) {
+ MessageLayout::Size case_offset =
+ layout.GetOneofCaseOffset(field->real_containing_oneof());
+ if (case_offset.size64 > 0xffff) return false;
+ assert(field->number() < 256);
+ data |= field->number() << 24;
+ data |= case_offset.size64 << 32;
+ } else {
+ uint64_t hasbit_index = 63; // No hasbit (set a high, unused bit).
+ if (layout.HasHasbit(field)) {
+ hasbit_index = layout.GetHasbitIndex(field);
+ if (hasbit_index > 31) return false;
+ }
+ data |= hasbit_index << 24;
+ }
+
+ if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
+ SubmsgArray submsg_array(message);
+ uint64_t idx = submsg_array.GetIndex(field);
+ if (idx > 255) return false;
+ data |= idx << 16;
+
+ std::string size_ceil = "max";
+ size_t size = SIZE_MAX;
+ if (field->message_type()->file() == field->file()) {
+ // We can only be guaranteed the size of the sub-message if it is in the
+ // same file as us. We could relax this to increase the speed of
+ // cross-file sub-message parsing if we are comfortable requiring that
+ // users compile all messages at the same time.
+ MessageLayout sub_layout(field->message_type());
+ size = sub_layout.message_size().size64 + 8;
+ }
+ std::vector<size_t> breaks = {64, 128, 192, 256};
+ for (auto brk : breaks) {
+ if (size <= brk) {
+ size_ceil = std::to_string(brk);
+ break;
+ }
+ }
+ ent.first = absl::Substitute("upb_p$0$1_$2bt_max$3b", cardinality, type,
+ expected_tag > 0xff ? "2" : "1", size_ceil);
+
+ } else {
+ ent.first = absl::Substitute("upb_p$0$1_$2bt", cardinality, type,
+ expected_tag > 0xff ? "2" : "1");
+ }
+ ent.second = data;
+ return true;
+}
+
+std::vector<TableEntry> FastDecodeTable(const protobuf::Descriptor* message,
+ const MessageLayout& layout) {
+ std::vector<TableEntry> table;
+ for (const auto field : FieldHotnessOrder(message)) {
+ TableEntry ent;
+ int slot = GetTableSlot(field);
+ // std::cerr << "table slot: " << field->number() << ": " << slot << "\n";
+ if (slot < 0) {
+ // Tag can't fit in the table.
+ continue;
+ }
+ if (!TryFillTableEntry(message, layout, field, ent)) {
+ // Unsupported field type or offset, hasbit index, etc. doesn't fit.
+ continue;
+ }
+ while ((size_t)slot >= table.size()) {
+ size_t size = std::max(static_cast<size_t>(1), table.size() * 2);
+ table.resize(size, TableEntry{"fastdecode_generic", 0});
+ }
+ if (table[slot].first != "fastdecode_generic") {
+ // A hotter field already filled this slot.
+ continue;
+ }
+ table[slot] = ent;
+ }
+ return table;
+}
+
+void WriteSource(const protobuf::FileDescriptor* file, Output& output,
+ bool fasttable_enabled) {
EmitFileWarning(file, output);
output(
@@ -827,14 +1023,34 @@
output("};\n\n");
}
+ std::vector<TableEntry> table;
+ uint8_t table_mask = -1;
+
+ if (fasttable_enabled) {
+ table = FastDecodeTable(message, layout);
+ }
+
+ if (table.size() > 1) {
+ assert((table.size() & (table.size() - 1)) == 0);
+ table_mask = (table.size() - 1) << 3;
+ }
+
output("const upb_msglayout $0 = {\n", MessageInit(message));
output(" $0,\n", submsgs_array_ref);
output(" $0,\n", fields_array_ref);
- output(" $0, $1, $2,\n", GetSizeInit(layout.message_size()),
+ output(" $0, $1, $2, $3,\n", GetSizeInit(layout.message_size()),
field_number_order.size(),
- "false" // TODO: extendable
+ "false", // TODO: extendable
+ table_mask
);
-
+ if (!table.empty()) {
+ output(" UPB_FASTTABLE_INIT({\n");
+ for (const auto& ent : table) {
+ output(" {0x$1, &$0},\n", ent.first,
+ absl::StrCat(absl::Hex(ent.second, absl::kZeroPad16)));
+ }
+ output(" }),\n");
+ }
output("};\n\n");
}
@@ -964,14 +1180,15 @@
}
bool Generator::Generate(const protobuf::FileDescriptor* file,
- const std::string& /* parameter */,
+ const std::string& parameter,
protoc::GeneratorContext* context,
std::string* /* error */) const {
+ bool fasttable_enabled = parameter == "fasttable";
Output h_output(context->Open(HeaderFilename(file->name())));
WriteHeader(file, h_output);
Output c_output(context->Open(SourceFilename(file->name())));
- WriteSource(file, c_output);
+ WriteSource(file, c_output, fasttable_enabled);
Output h_def_output(context->Open(DefHeaderFilename(file->name())));
WriteDefHeader(file, h_def_output);
diff --git a/upbc/main.cc b/upbc/main.cc
index a9682a9..3a38937 100644
--- a/upbc/main.cc
+++ b/upbc/main.cc
@@ -1,5 +1,5 @@
-#include <google/protobuf/compiler/plugin.h>
+#include "google/protobuf/compiler/plugin.h"
#include "upbc/generator.h"
diff --git a/upbc/message_layout.cc b/upbc/message_layout.cc
index 2a4fdbf..3d35448 100644
--- a/upbc/message_layout.cc
+++ b/upbc/message_layout.cc
@@ -24,9 +24,7 @@
}
bool MessageLayout::HasHasbit(const protobuf::FieldDescriptor* field) {
- return field->file()->syntax() == protobuf::FileDescriptor::SYNTAX_PROTO2 &&
- field->label() != protobuf::FieldDescriptor::LABEL_REPEATED &&
- !field->containing_oneof() &&
+ return field->has_presence() && !field->real_containing_oneof() &&
!field->containing_type()->options().map_entry();
}
@@ -110,7 +108,7 @@
void MessageLayout::ComputeLayout(const protobuf::Descriptor* descriptor) {
size_ = Size{0, 0};
- maxalign_ = Size{0, 0};
+ maxalign_ = Size{8, 8};
if (descriptor->options().map_entry()) {
// Map entries aren't actually stored, they are only used during parsing.
@@ -145,7 +143,7 @@
// Place/count hasbits.
int hasbit_count = 0;
- for (auto field : field_order) {
+ for (auto field : FieldHotnessOrder(descriptor)) {
if (HasHasbit(field)) {
// We don't use hasbit 0, so that 0 can indicate "no presence" in the
// table. This wastes one hasbit, but we don't worry about it for now.
diff --git a/upbc/message_layout.h b/upbc/message_layout.h
index c2446a0..f257a96 100644
--- a/upbc/message_layout.h
+++ b/upbc/message_layout.h
@@ -102,6 +102,23 @@
Size size_;
};
+// Returns fields in order of "hotness", eg. how frequently they appear in
+// serialized payloads. Ideally this will use a profile. When we don't have
+// that, we assume that fields with smaller numbers are used more frequently.
+inline std::vector<const google::protobuf::FieldDescriptor*> FieldHotnessOrder(
+ const google::protobuf::Descriptor* message) {
+ std::vector<const google::protobuf::FieldDescriptor*> fields;
+ for (int i = 0; i < message->field_count(); i++) {
+ fields.push_back(message->field(i));
+ }
+ std::sort(fields.begin(), fields.end(),
+ [](const google::protobuf::FieldDescriptor* a,
+ const google::protobuf::FieldDescriptor* b) {
+ return a->number() < b->number();
+ });
+ return fields;
+}
+
} // namespace upbc
#endif // UPBC_MESSAGE_LAYOUT_H