ruby_memprofiler_pprof 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
- data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
- data/ext/ruby_memprofiler_pprof/compat.c +182 -0
- data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
- data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
- data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
- data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
- data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
- data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
- data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
- data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
- data/lib/ruby_memprofiler_pprof/version.rb +5 -0
- data/lib/ruby_memprofiler_pprof.rb +8 -0
- data/libexec/ruby_memprofiler_pprof_profile +16 -0
- metadata +257 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
|
12
|
+
* * Neither the name of Google LLC nor the
|
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
|
14
|
+
* derived from this software without specific prior written permission.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#include "upb/util/compare.h"
|
|
29
|
+
|
|
30
|
+
#include <setjmp.h>
|
|
31
|
+
#include <stdbool.h>
|
|
32
|
+
|
|
33
|
+
#include "upb/port_def.inc"
|
|
34
|
+
|
|
35
|
+
struct upb_UnknownFields;
|
|
36
|
+
typedef struct upb_UnknownFields upb_UnknownFields;
|
|
37
|
+
|
|
38
|
+
typedef struct {
|
|
39
|
+
uint32_t tag;
|
|
40
|
+
union {
|
|
41
|
+
uint64_t varint;
|
|
42
|
+
uint64_t uint64;
|
|
43
|
+
uint32_t uint32;
|
|
44
|
+
upb_StringView delimited;
|
|
45
|
+
upb_UnknownFields* group;
|
|
46
|
+
} data;
|
|
47
|
+
} upb_UnknownField;
|
|
48
|
+
|
|
49
|
+
struct upb_UnknownFields {
|
|
50
|
+
size_t size;
|
|
51
|
+
size_t capacity;
|
|
52
|
+
upb_UnknownField* fields;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
typedef struct {
|
|
56
|
+
const char* end;
|
|
57
|
+
upb_Arena* arena;
|
|
58
|
+
upb_UnknownField* tmp;
|
|
59
|
+
size_t tmp_size;
|
|
60
|
+
int depth;
|
|
61
|
+
jmp_buf err;
|
|
62
|
+
} upb_UnknownField_Context;
|
|
63
|
+
|
|
64
|
+
static void upb_UnknownFields_Grow(upb_UnknownField_Context* ctx,
|
|
65
|
+
upb_UnknownField** base,
|
|
66
|
+
upb_UnknownField** ptr,
|
|
67
|
+
upb_UnknownField** end) {
|
|
68
|
+
size_t old = (*ptr - *base);
|
|
69
|
+
size_t new = UPB_MAX(4, old * 2);
|
|
70
|
+
|
|
71
|
+
*base = upb_Arena_Realloc(ctx->arena, *base, old * sizeof(**base),
|
|
72
|
+
new * sizeof(**base));
|
|
73
|
+
if (!*base) UPB_LONGJMP(ctx->err, kUpb_UnknownCompareResult_OutOfMemory);
|
|
74
|
+
|
|
75
|
+
*ptr = *base + old;
|
|
76
|
+
*end = *base + new;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static const char* upb_UnknownFields_ParseVarint(const char* ptr,
|
|
80
|
+
const char* limit,
|
|
81
|
+
uint64_t* val) {
|
|
82
|
+
uint8_t byte;
|
|
83
|
+
int bitpos = 0;
|
|
84
|
+
*val = 0;
|
|
85
|
+
|
|
86
|
+
do {
|
|
87
|
+
// Unknown field data must be valid.
|
|
88
|
+
UPB_ASSERT(bitpos < 70 && ptr < limit);
|
|
89
|
+
byte = *ptr;
|
|
90
|
+
*val |= (uint64_t)(byte & 0x7F) << bitpos;
|
|
91
|
+
ptr++;
|
|
92
|
+
bitpos += 7;
|
|
93
|
+
} while (byte & 0x80);
|
|
94
|
+
|
|
95
|
+
return ptr;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// We have to implement our own sort here, since qsort() is not an in-order
|
|
99
|
+
// sort. Here we use merge sort, the simplest in-order sort.
|
|
100
|
+
static void upb_UnknownFields_Merge(upb_UnknownField* arr, size_t start,
|
|
101
|
+
size_t mid, size_t end,
|
|
102
|
+
upb_UnknownField* tmp) {
|
|
103
|
+
memcpy(tmp, &arr[start], (end - start) * sizeof(*tmp));
|
|
104
|
+
|
|
105
|
+
upb_UnknownField* ptr1 = tmp;
|
|
106
|
+
upb_UnknownField* end1 = &tmp[mid - start];
|
|
107
|
+
upb_UnknownField* ptr2 = &tmp[mid - start];
|
|
108
|
+
upb_UnknownField* end2 = &tmp[end - start];
|
|
109
|
+
upb_UnknownField* out = &arr[start];
|
|
110
|
+
|
|
111
|
+
while (ptr1 < end1 && ptr2 < end2) {
|
|
112
|
+
if (ptr1->tag <= ptr2->tag) {
|
|
113
|
+
*out++ = *ptr1++;
|
|
114
|
+
} else {
|
|
115
|
+
*out++ = *ptr2++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (ptr1 < end1) {
|
|
120
|
+
memcpy(out, ptr1, (end1 - ptr1) * sizeof(*out));
|
|
121
|
+
} else if (ptr2 < end2) {
|
|
122
|
+
memcpy(out, ptr1, (end2 - ptr2) * sizeof(*out));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static void upb_UnknownFields_SortRecursive(upb_UnknownField* arr, size_t start,
|
|
127
|
+
size_t end, upb_UnknownField* tmp) {
|
|
128
|
+
if (end - start > 1) {
|
|
129
|
+
size_t mid = start + ((end - start) / 2);
|
|
130
|
+
upb_UnknownFields_SortRecursive(arr, start, mid, tmp);
|
|
131
|
+
upb_UnknownFields_SortRecursive(arr, mid, end, tmp);
|
|
132
|
+
upb_UnknownFields_Merge(arr, start, mid, end, tmp);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static void upb_UnknownFields_Sort(upb_UnknownField_Context* ctx,
|
|
137
|
+
upb_UnknownFields* fields) {
|
|
138
|
+
if (ctx->tmp_size < fields->size) {
|
|
139
|
+
ctx->tmp_size = UPB_MAX(8, ctx->tmp_size);
|
|
140
|
+
while (ctx->tmp_size < fields->size) ctx->tmp_size *= 2;
|
|
141
|
+
ctx->tmp = realloc(ctx->tmp, ctx->tmp_size * sizeof(*ctx->tmp));
|
|
142
|
+
}
|
|
143
|
+
upb_UnknownFields_SortRecursive(fields->fields, 0, fields->size, ctx->tmp);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static upb_UnknownFields* upb_UnknownFields_DoBuild(
|
|
147
|
+
upb_UnknownField_Context* ctx, const char** buf) {
|
|
148
|
+
upb_UnknownField* arr_base = NULL;
|
|
149
|
+
upb_UnknownField* arr_ptr = NULL;
|
|
150
|
+
upb_UnknownField* arr_end = NULL;
|
|
151
|
+
const char* ptr = *buf;
|
|
152
|
+
uint32_t last_tag = 0;
|
|
153
|
+
bool sorted = true;
|
|
154
|
+
while (ptr < ctx->end) {
|
|
155
|
+
uint64_t tag;
|
|
156
|
+
ptr = upb_UnknownFields_ParseVarint(ptr, ctx->end, &tag);
|
|
157
|
+
UPB_ASSERT(tag <= UINT32_MAX);
|
|
158
|
+
int wire_type = tag & 7;
|
|
159
|
+
if (wire_type == kUpb_WireType_EndGroup) break;
|
|
160
|
+
if (tag < last_tag) sorted = false;
|
|
161
|
+
last_tag = tag;
|
|
162
|
+
|
|
163
|
+
if (arr_ptr == arr_end) {
|
|
164
|
+
upb_UnknownFields_Grow(ctx, &arr_base, &arr_ptr, &arr_end);
|
|
165
|
+
}
|
|
166
|
+
upb_UnknownField* field = arr_ptr;
|
|
167
|
+
field->tag = tag;
|
|
168
|
+
arr_ptr++;
|
|
169
|
+
|
|
170
|
+
switch (wire_type) {
|
|
171
|
+
case kUpb_WireType_Varint:
|
|
172
|
+
ptr = upb_UnknownFields_ParseVarint(ptr, ctx->end, &field->data.varint);
|
|
173
|
+
break;
|
|
174
|
+
case kUpb_WireType_64Bit:
|
|
175
|
+
UPB_ASSERT(ctx->end - ptr >= 8);
|
|
176
|
+
memcpy(&field->data.uint64, ptr, 8);
|
|
177
|
+
ptr += 8;
|
|
178
|
+
break;
|
|
179
|
+
case kUpb_WireType_32Bit:
|
|
180
|
+
UPB_ASSERT(ctx->end - ptr >= 4);
|
|
181
|
+
memcpy(&field->data.uint32, ptr, 4);
|
|
182
|
+
ptr += 4;
|
|
183
|
+
break;
|
|
184
|
+
case kUpb_WireType_Delimited: {
|
|
185
|
+
uint64_t size;
|
|
186
|
+
ptr = upb_UnknownFields_ParseVarint(ptr, ctx->end, &size);
|
|
187
|
+
UPB_ASSERT(ctx->end - ptr >= size);
|
|
188
|
+
field->data.delimited.data = ptr;
|
|
189
|
+
field->data.delimited.size = size;
|
|
190
|
+
ptr += size;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case kUpb_WireType_StartGroup:
|
|
194
|
+
if (--ctx->depth == 0) {
|
|
195
|
+
UPB_LONGJMP(ctx->err, kUpb_UnknownCompareResult_MaxDepthExceeded);
|
|
196
|
+
}
|
|
197
|
+
field->data.group = upb_UnknownFields_DoBuild(ctx, &ptr);
|
|
198
|
+
ctx->depth++;
|
|
199
|
+
break;
|
|
200
|
+
default:
|
|
201
|
+
UPB_UNREACHABLE();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
*buf = ptr;
|
|
206
|
+
upb_UnknownFields* ret = upb_Arena_Malloc(ctx->arena, sizeof(*ret));
|
|
207
|
+
if (!ret) UPB_LONGJMP(ctx->err, kUpb_UnknownCompareResult_OutOfMemory);
|
|
208
|
+
ret->fields = arr_base;
|
|
209
|
+
ret->size = arr_ptr - arr_base;
|
|
210
|
+
ret->capacity = arr_end - arr_base;
|
|
211
|
+
if (!sorted) {
|
|
212
|
+
upb_UnknownFields_Sort(ctx, ret);
|
|
213
|
+
}
|
|
214
|
+
return ret;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Builds a upb_UnknownFields data structure from the binary data in buf.
|
|
218
|
+
static upb_UnknownFields* upb_UnknownFields_Build(upb_UnknownField_Context* ctx,
|
|
219
|
+
const char* buf,
|
|
220
|
+
size_t size) {
|
|
221
|
+
ctx->end = buf + size;
|
|
222
|
+
upb_UnknownFields* fields = upb_UnknownFields_DoBuild(ctx, &buf);
|
|
223
|
+
UPB_ASSERT(buf == ctx->end);
|
|
224
|
+
return fields;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Compares two sorted upb_UnknwonFields structures for equality.
|
|
228
|
+
static bool upb_UnknownFields_IsEqual(const upb_UnknownFields* uf1,
|
|
229
|
+
const upb_UnknownFields* uf2) {
|
|
230
|
+
if (uf1->size != uf2->size) return false;
|
|
231
|
+
for (size_t i = 0, n = uf1->size; i < n; i++) {
|
|
232
|
+
upb_UnknownField* f1 = &uf1->fields[i];
|
|
233
|
+
upb_UnknownField* f2 = &uf2->fields[i];
|
|
234
|
+
if (f1->tag != f2->tag) return false;
|
|
235
|
+
int wire_type = f1->tag & 7;
|
|
236
|
+
switch (wire_type) {
|
|
237
|
+
case kUpb_WireType_Varint:
|
|
238
|
+
if (f1->data.varint != f2->data.varint) return false;
|
|
239
|
+
break;
|
|
240
|
+
case kUpb_WireType_64Bit:
|
|
241
|
+
if (f1->data.uint64 != f2->data.uint64) return false;
|
|
242
|
+
break;
|
|
243
|
+
case kUpb_WireType_32Bit:
|
|
244
|
+
if (f1->data.uint32 != f2->data.uint32) return false;
|
|
245
|
+
break;
|
|
246
|
+
case kUpb_WireType_Delimited:
|
|
247
|
+
if (!upb_StringView_IsEqual(f1->data.delimited, f2->data.delimited)) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
case kUpb_WireType_StartGroup:
|
|
252
|
+
if (!upb_UnknownFields_IsEqual(f1->data.group, f2->data.group)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
default:
|
|
257
|
+
UPB_UNREACHABLE();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
upb_UnknownCompareResult upb_Message_UnknownFieldsAreEqual(const char* buf1,
|
|
264
|
+
size_t size1,
|
|
265
|
+
const char* buf2,
|
|
266
|
+
size_t size2,
|
|
267
|
+
int max_depth) {
|
|
268
|
+
if (size1 == 0 && size2 == 0) return kUpb_UnknownCompareResult_Equal;
|
|
269
|
+
if (size1 == 0 || size2 == 0) return kUpb_UnknownCompareResult_NotEqual;
|
|
270
|
+
if (memcmp(buf1, buf2, size1) == 0) return kUpb_UnknownCompareResult_Equal;
|
|
271
|
+
|
|
272
|
+
upb_UnknownField_Context ctx = {
|
|
273
|
+
.arena = upb_Arena_New(),
|
|
274
|
+
.depth = max_depth,
|
|
275
|
+
.tmp = NULL,
|
|
276
|
+
.tmp_size = 0,
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
if (!ctx.arena) return kUpb_UnknownCompareResult_OutOfMemory;
|
|
280
|
+
|
|
281
|
+
int ret = UPB_SETJMP(ctx.err);
|
|
282
|
+
|
|
283
|
+
if (UPB_LIKELY(ret == 0)) {
|
|
284
|
+
// First build both unknown fields into a sorted data structure (similar
|
|
285
|
+
// to the UnknownFieldSet in C++).
|
|
286
|
+
upb_UnknownFields* uf1 = upb_UnknownFields_Build(&ctx, buf1, size1);
|
|
287
|
+
upb_UnknownFields* uf2 = upb_UnknownFields_Build(&ctx, buf2, size2);
|
|
288
|
+
|
|
289
|
+
// Now perform the equality check on the sorted structures.
|
|
290
|
+
if (upb_UnknownFields_IsEqual(uf1, uf2)) {
|
|
291
|
+
ret = kUpb_UnknownCompareResult_Equal;
|
|
292
|
+
} else {
|
|
293
|
+
ret = kUpb_UnknownCompareResult_NotEqual;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
upb_Arena_Free(ctx.arena);
|
|
298
|
+
free(ctx.tmp);
|
|
299
|
+
return ret;
|
|
300
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
|
12
|
+
* * Neither the name of Google LLC nor the
|
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
|
14
|
+
* derived from this software without specific prior written permission.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifndef UPB_UTIL_COMPARE_H_
|
|
29
|
+
#define UPB_UTIL_COMPARE_H_
|
|
30
|
+
|
|
31
|
+
#include "upb/def.h"
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
extern "C" {
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
// Returns true if unknown fields from the two messages are equal when sorted
|
|
38
|
+
// and varints are made canonical.
|
|
39
|
+
//
|
|
40
|
+
// This function is discouraged, as the comparison is inherently lossy without
|
|
41
|
+
// schema data:
|
|
42
|
+
//
|
|
43
|
+
// 1. We don't know whether delimited fields are sub-messages. Unknown
|
|
44
|
+
// sub-messages will therefore not have their fields sorted and varints
|
|
45
|
+
// canonicalized.
|
|
46
|
+
// 2. We don't know about oneof/non-repeated fields, which should semantically
|
|
47
|
+
// discard every value except the last.
|
|
48
|
+
|
|
49
|
+
typedef enum {
|
|
50
|
+
kUpb_UnknownCompareResult_Equal = 0,
|
|
51
|
+
kUpb_UnknownCompareResult_NotEqual = 1,
|
|
52
|
+
kUpb_UnknownCompareResult_OutOfMemory = 2,
|
|
53
|
+
kUpb_UnknownCompareResult_MaxDepthExceeded = 3,
|
|
54
|
+
} upb_UnknownCompareResult;
|
|
55
|
+
|
|
56
|
+
upb_UnknownCompareResult upb_Message_UnknownFieldsAreEqual(const char* buf1,
|
|
57
|
+
size_t size1,
|
|
58
|
+
const char* buf2,
|
|
59
|
+
size_t size2,
|
|
60
|
+
int max_depth);
|
|
61
|
+
|
|
62
|
+
#ifdef __cplusplus
|
|
63
|
+
} /* extern "C" */
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#endif /* UPB_UTIL_COMPARE_H_ */
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
|
12
|
+
* * Neither the name of Google LLC nor the
|
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
|
14
|
+
* derived from this software without specific prior written permission.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#include "upb/util/compare.h"
|
|
29
|
+
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
|
|
32
|
+
#include <string_view>
|
|
33
|
+
#include <vector>
|
|
34
|
+
|
|
35
|
+
#include "absl/strings/string_view.h"
|
|
36
|
+
#include "gmock/gmock.h"
|
|
37
|
+
#include "gtest/gtest.h"
|
|
38
|
+
|
|
39
|
+
struct UnknownField;
|
|
40
|
+
|
|
41
|
+
using UnknownFields = std::vector<UnknownField>;
|
|
42
|
+
|
|
43
|
+
enum class UnknownFieldType {
|
|
44
|
+
kVarint,
|
|
45
|
+
kLongVarint, // Over-encoded to have distinct wire format.
|
|
46
|
+
kDelimited,
|
|
47
|
+
kFixed64,
|
|
48
|
+
kFixed32,
|
|
49
|
+
kGroup,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
union UnknownFieldValue {
|
|
53
|
+
uint64_t varint;
|
|
54
|
+
uint64_t fixed64;
|
|
55
|
+
uint32_t fixed32;
|
|
56
|
+
// NULL-terminated (strings must not have embedded NULL).
|
|
57
|
+
const char* delimited;
|
|
58
|
+
UnknownFields* group;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
struct TypeAndValue {
|
|
62
|
+
UnknownFieldType type;
|
|
63
|
+
UnknownFieldValue value;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
struct UnknownField {
|
|
67
|
+
uint32_t field_number;
|
|
68
|
+
TypeAndValue value;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
TypeAndValue Varint(uint64_t val) {
|
|
72
|
+
TypeAndValue ret{UnknownFieldType::kVarint};
|
|
73
|
+
ret.value.varint = val;
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
TypeAndValue LongVarint(uint64_t val) {
|
|
78
|
+
TypeAndValue ret{UnknownFieldType::kLongVarint};
|
|
79
|
+
ret.value.varint = val;
|
|
80
|
+
return ret;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
TypeAndValue Fixed64(uint64_t val) {
|
|
84
|
+
TypeAndValue ret{UnknownFieldType::kFixed64};
|
|
85
|
+
ret.value.fixed64 = val;
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
TypeAndValue Fixed32(uint32_t val) {
|
|
90
|
+
TypeAndValue ret{UnknownFieldType::kFixed32};
|
|
91
|
+
ret.value.fixed32 = val;
|
|
92
|
+
return ret;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
TypeAndValue Delimited(const char* val) {
|
|
96
|
+
TypeAndValue ret{UnknownFieldType::kDelimited};
|
|
97
|
+
ret.value.delimited = val;
|
|
98
|
+
return ret;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
TypeAndValue Group(UnknownFields nested) {
|
|
102
|
+
TypeAndValue ret{UnknownFieldType::kGroup};
|
|
103
|
+
ret.value.group = &nested;
|
|
104
|
+
return ret;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void EncodeVarint(uint64_t val, std::string* str) {
|
|
108
|
+
do {
|
|
109
|
+
char byte = val & 0x7fU;
|
|
110
|
+
val >>= 7;
|
|
111
|
+
if (val) byte |= 0x80U;
|
|
112
|
+
str->push_back(byte);
|
|
113
|
+
} while (val);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
std::string ToBinaryPayload(const UnknownFields& fields) {
|
|
117
|
+
static const upb_WireType wire_types[] = {
|
|
118
|
+
kUpb_WireType_Varint, kUpb_WireType_Varint, kUpb_WireType_Delimited,
|
|
119
|
+
kUpb_WireType_64Bit, kUpb_WireType_32Bit, kUpb_WireType_StartGroup,
|
|
120
|
+
};
|
|
121
|
+
std::string ret;
|
|
122
|
+
|
|
123
|
+
for (const auto& field : fields) {
|
|
124
|
+
uint32_t tag = field.field_number << 3 |
|
|
125
|
+
(wire_types[static_cast<int>(field.value.type)]);
|
|
126
|
+
EncodeVarint(tag, &ret);
|
|
127
|
+
switch (field.value.type) {
|
|
128
|
+
case UnknownFieldType::kVarint:
|
|
129
|
+
EncodeVarint(field.value.value.varint, &ret);
|
|
130
|
+
break;
|
|
131
|
+
case UnknownFieldType::kLongVarint:
|
|
132
|
+
EncodeVarint(field.value.value.varint, &ret);
|
|
133
|
+
ret.back() |= 0x80;
|
|
134
|
+
ret.push_back(0);
|
|
135
|
+
break;
|
|
136
|
+
case UnknownFieldType::kDelimited:
|
|
137
|
+
EncodeVarint(strlen(field.value.value.delimited), &ret);
|
|
138
|
+
ret.append(field.value.value.delimited);
|
|
139
|
+
break;
|
|
140
|
+
case UnknownFieldType::kFixed64: {
|
|
141
|
+
uint64_t val = _upb_BigEndian_Swap64(field.value.value.fixed64);
|
|
142
|
+
ret.append(reinterpret_cast<const char*>(&val), sizeof(val));
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case UnknownFieldType::kFixed32: {
|
|
146
|
+
uint32_t val = _upb_BigEndian_Swap32(field.value.value.fixed32);
|
|
147
|
+
ret.append(reinterpret_cast<const char*>(&val), sizeof(val));
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case UnknownFieldType::kGroup: {
|
|
151
|
+
uint32_t end_tag = field.field_number << 3 | kUpb_WireType_EndGroup;
|
|
152
|
+
ret.append(ToBinaryPayload(*field.value.value.group));
|
|
153
|
+
EncodeVarint(end_tag, &ret);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return ret;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
upb_UnknownCompareResult CompareUnknownWithMaxDepth(UnknownFields uf1,
|
|
163
|
+
UnknownFields uf2,
|
|
164
|
+
int max_depth) {
|
|
165
|
+
std::string buf1 = ToBinaryPayload(uf1);
|
|
166
|
+
std::string buf2 = ToBinaryPayload(uf2);
|
|
167
|
+
return upb_Message_UnknownFieldsAreEqual(buf1.data(), buf1.size(),
|
|
168
|
+
buf2.data(), buf2.size(), max_depth);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
upb_UnknownCompareResult CompareUnknown(UnknownFields uf1, UnknownFields uf2) {
|
|
172
|
+
return CompareUnknownWithMaxDepth(uf1, uf2, 64);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
TEST(CompareTest, UnknownFieldsReflexive) {
|
|
176
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_Equal, CompareUnknown({}, {}));
|
|
177
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_Equal,
|
|
178
|
+
CompareUnknown({{1, Varint(123)}, {2, Fixed32(456)}},
|
|
179
|
+
{{1, Varint(123)}, {2, Fixed32(456)}}));
|
|
180
|
+
EXPECT_EQ(
|
|
181
|
+
kUpb_UnknownCompareResult_Equal,
|
|
182
|
+
CompareUnknown(
|
|
183
|
+
{{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}},
|
|
184
|
+
{{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}}));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
TEST(CompareTest, UnknownFieldsOrdering) {
|
|
188
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_Equal,
|
|
189
|
+
CompareUnknown({{1, Varint(111)},
|
|
190
|
+
{2, Delimited("ABC")},
|
|
191
|
+
{3, Fixed32(456)},
|
|
192
|
+
{4, Fixed64(123)},
|
|
193
|
+
{5, Group({})}},
|
|
194
|
+
{{5, Group({})},
|
|
195
|
+
{4, Fixed64(123)},
|
|
196
|
+
{3, Fixed32(456)},
|
|
197
|
+
{2, Delimited("ABC")},
|
|
198
|
+
{1, Varint(111)}}));
|
|
199
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_NotEqual,
|
|
200
|
+
CompareUnknown({{1, Varint(111)},
|
|
201
|
+
{2, Delimited("ABC")},
|
|
202
|
+
{3, Fixed32(456)},
|
|
203
|
+
{4, Fixed64(123)},
|
|
204
|
+
{5, Group({})}},
|
|
205
|
+
{{5, Group({})},
|
|
206
|
+
{4, Fixed64(123)},
|
|
207
|
+
{3, Fixed32(455)}, // Small difference.
|
|
208
|
+
{2, Delimited("ABC")},
|
|
209
|
+
{1, Varint(111)}}));
|
|
210
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_Equal,
|
|
211
|
+
CompareUnknown({{3, Fixed32(456)}, {4, Fixed64(123)}},
|
|
212
|
+
{{4, Fixed64(123)}, {3, Fixed32(456)}}));
|
|
213
|
+
EXPECT_EQ(
|
|
214
|
+
kUpb_UnknownCompareResult_Equal,
|
|
215
|
+
CompareUnknown(
|
|
216
|
+
{{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}},
|
|
217
|
+
{{1, Group({{2, Group({{4, Fixed64(123)}, {3, Fixed32(456)}})}})}}));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
TEST(CompareTest, LongVarint) {
|
|
221
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_Equal,
|
|
222
|
+
CompareUnknown({{1, LongVarint(123)}, {2, LongVarint(456)}},
|
|
223
|
+
{{1, Varint(123)}, {2, Varint(456)}}));
|
|
224
|
+
EXPECT_EQ(kUpb_UnknownCompareResult_Equal,
|
|
225
|
+
CompareUnknown({{2, LongVarint(456)}, {1, LongVarint(123)}},
|
|
226
|
+
{{1, Varint(123)}, {2, Varint(456)}}));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
TEST(CompareTest, MaxDepth) {
|
|
230
|
+
EXPECT_EQ(
|
|
231
|
+
kUpb_UnknownCompareResult_MaxDepthExceeded,
|
|
232
|
+
CompareUnknownWithMaxDepth(
|
|
233
|
+
{{1, Group({{2, Group({{3, Fixed32(456)}, {4, Fixed64(123)}})}})}},
|
|
234
|
+
{{1, Group({{2, Group({{4, Fixed64(123)}, {3, Fixed32(456)}})}})}},
|
|
235
|
+
2));
|
|
236
|
+
}
|