ruby_memprofiler_pprof 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,94 @@
|
|
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_REQUIRED_FIELDS_H_
|
29
|
+
#define UPB_UTIL_REQUIRED_FIELDS_H_
|
30
|
+
|
31
|
+
#include "upb/def.h"
|
32
|
+
#include "upb/reflection.h"
|
33
|
+
|
34
|
+
/* Must be last. */
|
35
|
+
#include "upb/port_def.inc"
|
36
|
+
|
37
|
+
#ifdef __cplusplus
|
38
|
+
extern "C" {
|
39
|
+
#endif
|
40
|
+
|
41
|
+
// A FieldPath can be encoded as an array of upb_FieldPathEntry, in the
|
42
|
+
// following format:
|
43
|
+
// { {.field = f1}, {.field = f2} } # f1.f2
|
44
|
+
// { {.field = f1}, {.index = 5}, {.field = f2} } # f1[5].f2
|
45
|
+
// { {.field = f1}, {.key = "abc"}, {.field = f2} } # f1["abc"].f2
|
46
|
+
//
|
47
|
+
// Users must look at the type of `field` to know if an index or map key
|
48
|
+
// follows.
|
49
|
+
//
|
50
|
+
// A field path may be NULL-terminated, in which case a NULL field indicates
|
51
|
+
// the end of the field path.
|
52
|
+
typedef union {
|
53
|
+
const upb_FieldDef* field;
|
54
|
+
size_t array_index;
|
55
|
+
upb_MessageValue map_key;
|
56
|
+
} upb_FieldPathEntry;
|
57
|
+
|
58
|
+
// Writes a string representing `*path` to `buf` in the following textual
|
59
|
+
// format:
|
60
|
+
// foo.bar # Regular fields
|
61
|
+
// repeated_baz[2].bar # Repeated field
|
62
|
+
// int32_msg_map[5].bar # Integer-keyed map
|
63
|
+
// string_msg_map["abc"] # String-keyed map
|
64
|
+
// bool_msg_map[true] # Bool-keyed map
|
65
|
+
//
|
66
|
+
// The input array `*path` must be NULL-terminated. The pointer `*path` will be
|
67
|
+
// updated to point to one past the terminating NULL pointer of the input array.
|
68
|
+
//
|
69
|
+
// The output buffer `buf` will always be NULL-terminated. If the output data
|
70
|
+
// (including NULL terminator) exceeds `size`, the result will be truncated.
|
71
|
+
// Returns the string length of the data we attempted to write, excluding the
|
72
|
+
// terminating NULL.
|
73
|
+
size_t upb_FieldPath_ToText(upb_FieldPathEntry** path, char* buf, size_t size);
|
74
|
+
|
75
|
+
// Checks whether `msg` or any of its children has unset required fields,
|
76
|
+
// returning `true` if any are found. `msg` may be NULL, in which case the
|
77
|
+
// message will be treated as empty.
|
78
|
+
//
|
79
|
+
// When this function returns true, `fields` is updated (if non-NULL) to point
|
80
|
+
// to a heap-allocated array encoding the field paths of the required fields
|
81
|
+
// that are missing. Each path is terminated with {.field = NULL}, and a final
|
82
|
+
// {.field = NULL} terminates the list of paths. The caller is responsible for
|
83
|
+
// freeing this array.
|
84
|
+
bool upb_util_HasUnsetRequired(const upb_Message* msg, const upb_MessageDef* m,
|
85
|
+
const upb_DefPool* ext_pool,
|
86
|
+
upb_FieldPathEntry** fields);
|
87
|
+
|
88
|
+
#ifdef __cplusplus
|
89
|
+
} /* extern "C" */
|
90
|
+
#endif
|
91
|
+
|
92
|
+
#include "upb/port_undef.inc"
|
93
|
+
|
94
|
+
#endif /* UPB_UTIL_REQUIRED_FIELDS_H_ */
|
@@ -0,0 +1,202 @@
|
|
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/required_fields.h"
|
29
|
+
|
30
|
+
#include "absl/strings/string_view.h"
|
31
|
+
#include "gmock/gmock.h"
|
32
|
+
#include "gtest/gtest.h"
|
33
|
+
#include "upb/def.hpp"
|
34
|
+
#include "upb/json_decode.h"
|
35
|
+
#include "upb/upb.hpp"
|
36
|
+
#include "upb/util/required_fields_test.upb.h"
|
37
|
+
#include "upb/util/required_fields_test.upbdefs.h"
|
38
|
+
|
39
|
+
std::vector<std::string> PathsToText(upb_FieldPathEntry* entry) {
|
40
|
+
std::vector<std::string> ret;
|
41
|
+
char buf[1024]; // Larger than anything we'll use in this test.
|
42
|
+
while (entry->field) {
|
43
|
+
upb_FieldPathEntry* before = entry;
|
44
|
+
size_t len = upb_FieldPath_ToText(&entry, buf, sizeof(buf));
|
45
|
+
EXPECT_LT(len, sizeof(buf));
|
46
|
+
assert(len <= sizeof(buf));
|
47
|
+
ret.push_back(buf);
|
48
|
+
|
49
|
+
// Ensure that we can have a short buffer and that it will be
|
50
|
+
// NULL-terminated.
|
51
|
+
char shortbuf[4];
|
52
|
+
size_t len2 = upb_FieldPath_ToText(&before, shortbuf, sizeof(shortbuf));
|
53
|
+
EXPECT_EQ(len, len2);
|
54
|
+
EXPECT_EQ(ret.back().substr(0, sizeof(shortbuf) - 1),
|
55
|
+
std::string(shortbuf));
|
56
|
+
}
|
57
|
+
return ret;
|
58
|
+
}
|
59
|
+
|
60
|
+
void CheckRequired(absl::string_view json,
|
61
|
+
const std::vector<std::string>& missing) {
|
62
|
+
upb::Arena arena;
|
63
|
+
upb::SymbolTable symtab;
|
64
|
+
upb_util_test_TestRequiredFields* test_msg =
|
65
|
+
upb_util_test_TestRequiredFields_new(arena.ptr());
|
66
|
+
upb::MessageDefPtr m(
|
67
|
+
upb_util_test_TestRequiredFields_getmsgdef(symtab.ptr()));
|
68
|
+
upb::Status status;
|
69
|
+
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), test_msg, m.ptr(),
|
70
|
+
symtab.ptr(), 0, arena.ptr(), status.ptr()))
|
71
|
+
<< status.error_message();
|
72
|
+
upb_FieldPathEntry* entries;
|
73
|
+
EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired(
|
74
|
+
test_msg, m.ptr(), symtab.ptr(), &entries));
|
75
|
+
EXPECT_EQ(missing, PathsToText(entries));
|
76
|
+
free(entries);
|
77
|
+
|
78
|
+
// Verify that we can pass a NULL pointer to entries when we don't care about
|
79
|
+
// them.
|
80
|
+
EXPECT_EQ(!missing.empty(),
|
81
|
+
upb_util_HasUnsetRequired(test_msg, m.ptr(), symtab.ptr(), NULL));
|
82
|
+
}
|
83
|
+
|
84
|
+
// message HasRequiredField {
|
85
|
+
// required int32 required_int32 = 1;
|
86
|
+
// }
|
87
|
+
//
|
88
|
+
// message TestRequiredFields {
|
89
|
+
// required EmptyMessage required_message = 1;
|
90
|
+
// optional TestRequiredFields optional_message = 2;
|
91
|
+
// repeated HasRequiredField repeated_message = 3;
|
92
|
+
// map<int32, HasRequiredField> map_int32_message = 4;
|
93
|
+
// }
|
94
|
+
TEST(RequiredFieldsTest, TestRequired) {
|
95
|
+
CheckRequired(R"json({})json", {"required_message"});
|
96
|
+
CheckRequired(R"json({"required_message": {}}")json", {});
|
97
|
+
CheckRequired(
|
98
|
+
R"json(
|
99
|
+
{
|
100
|
+
"optional_message": {}
|
101
|
+
}
|
102
|
+
)json",
|
103
|
+
{"required_message", "optional_message.required_message"});
|
104
|
+
|
105
|
+
// Repeated field.
|
106
|
+
CheckRequired(
|
107
|
+
R"json(
|
108
|
+
{
|
109
|
+
"optional_message": {
|
110
|
+
"repeated_message": [
|
111
|
+
{"required_int32": 1},
|
112
|
+
{},
|
113
|
+
{"required_int32": 2}
|
114
|
+
]
|
115
|
+
}
|
116
|
+
}
|
117
|
+
)json",
|
118
|
+
{"required_message", "optional_message.required_message",
|
119
|
+
"optional_message.repeated_message[1].required_int32"});
|
120
|
+
|
121
|
+
// Int32 map key.
|
122
|
+
CheckRequired(
|
123
|
+
R"json(
|
124
|
+
{
|
125
|
+
"required_message": {},
|
126
|
+
"map_int32_message": {
|
127
|
+
"1": {"required_int32": 1},
|
128
|
+
"5": {},
|
129
|
+
"9": {"required_int32": 1}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
)json",
|
133
|
+
{"map_int32_message[5].required_int32"});
|
134
|
+
|
135
|
+
// Int64 map key.
|
136
|
+
CheckRequired(
|
137
|
+
R"json(
|
138
|
+
{
|
139
|
+
"required_message": {},
|
140
|
+
"map_int64_message": {
|
141
|
+
"1": {"required_int32": 1},
|
142
|
+
"5": {},
|
143
|
+
"9": {"required_int32": 1}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
)json",
|
147
|
+
{"map_int64_message[5].required_int32"});
|
148
|
+
|
149
|
+
// Uint32 map key.
|
150
|
+
CheckRequired(
|
151
|
+
R"json(
|
152
|
+
{
|
153
|
+
"required_message": {},
|
154
|
+
"map_uint32_message": {
|
155
|
+
"1": {"required_int32": 1},
|
156
|
+
"5": {},
|
157
|
+
"9": {"required_int32": 1}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
)json",
|
161
|
+
{"map_uint32_message[5].required_int32"});
|
162
|
+
|
163
|
+
// Uint64 map key.
|
164
|
+
CheckRequired(
|
165
|
+
R"json(
|
166
|
+
{
|
167
|
+
"required_message": {},
|
168
|
+
"map_uint64_message": {
|
169
|
+
"1": {"required_int32": 1},
|
170
|
+
"5": {},
|
171
|
+
"9": {"required_int32": 1}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
)json",
|
175
|
+
{"map_uint64_message[5].required_int32"});
|
176
|
+
|
177
|
+
// Bool map key.
|
178
|
+
CheckRequired(
|
179
|
+
R"json(
|
180
|
+
{
|
181
|
+
"required_message": {},
|
182
|
+
"map_bool_message": {
|
183
|
+
"false": {"required_int32": 1},
|
184
|
+
"true": {}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
)json",
|
188
|
+
{"map_bool_message[true].required_int32"});
|
189
|
+
|
190
|
+
// String map key.
|
191
|
+
CheckRequired(
|
192
|
+
R"json(
|
193
|
+
{
|
194
|
+
"required_message": {},
|
195
|
+
"map_string_message": {
|
196
|
+
"abc": {"required_int32": 1},
|
197
|
+
"d\"ef": {}
|
198
|
+
}
|
199
|
+
}
|
200
|
+
)json",
|
201
|
+
{R"(map_string_message["d\"ef"].required_int32)"});
|
202
|
+
}
|
@@ -0,0 +1,48 @@
|
|
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
|
+
syntax = "proto2";
|
29
|
+
|
30
|
+
package upb_util_test;
|
31
|
+
|
32
|
+
message EmptyMessage {}
|
33
|
+
|
34
|
+
message HasRequiredField {
|
35
|
+
required int32 required_int32 = 1;
|
36
|
+
}
|
37
|
+
|
38
|
+
message TestRequiredFields {
|
39
|
+
required EmptyMessage required_message = 1;
|
40
|
+
optional TestRequiredFields optional_message = 2;
|
41
|
+
repeated HasRequiredField repeated_message = 3;
|
42
|
+
map<int32, HasRequiredField> map_int32_message = 4;
|
43
|
+
map<int64, HasRequiredField> map_int64_message = 5;
|
44
|
+
map<uint32, HasRequiredField> map_uint32_message = 6;
|
45
|
+
map<uint64, HasRequiredField> map_uint64_message = 7;
|
46
|
+
map<bool, HasRequiredField> map_bool_message = 8;
|
47
|
+
map<string, HasRequiredField> map_string_message = 9;
|
48
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Copyright (c) 2009-2021, Google LLC
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# * Redistributions of source code must retain the above copyright
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
8
|
+
# * Redistributions in binary form must reproduce the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
11
|
+
# * Neither the name of Google LLC nor the
|
12
|
+
# names of its contributors may be used to endorse or promote products
|
13
|
+
# derived from this software without specific prior written permission.
|
14
|
+
#
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
|
19
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
26
|
+
load(
|
27
|
+
"//bazel:build_defs.bzl",
|
28
|
+
"UPB_DEFAULT_CPPOPTS",
|
29
|
+
)
|
30
|
+
|
31
|
+
licenses(["notice"])
|
32
|
+
|
33
|
+
cc_library(
|
34
|
+
name = "common",
|
35
|
+
srcs = ["common.cc"],
|
36
|
+
hdrs = ["common.h"],
|
37
|
+
copts = UPB_DEFAULT_CPPOPTS,
|
38
|
+
deps = [
|
39
|
+
"@com_google_absl//absl/strings",
|
40
|
+
"@com_google_protobuf//:protobuf",
|
41
|
+
],
|
42
|
+
)
|
43
|
+
|
44
|
+
cc_binary(
|
45
|
+
name = "protoc-gen-upb",
|
46
|
+
srcs = ["protoc-gen-upb.cc"],
|
47
|
+
copts = UPB_DEFAULT_CPPOPTS,
|
48
|
+
visibility = ["//visibility:public"],
|
49
|
+
deps = [
|
50
|
+
":common",
|
51
|
+
"//:mini_table",
|
52
|
+
"//:port",
|
53
|
+
"//:upb",
|
54
|
+
"@com_google_absl//absl/base:core_headers",
|
55
|
+
"@com_google_absl//absl/container:flat_hash_map",
|
56
|
+
"@com_google_absl//absl/container:flat_hash_set",
|
57
|
+
"@com_google_absl//absl/strings",
|
58
|
+
"@com_google_protobuf//:protobuf",
|
59
|
+
"@com_google_protobuf//:protoc_lib",
|
60
|
+
],
|
61
|
+
)
|
62
|
+
|
63
|
+
cc_binary(
|
64
|
+
name = "protoc-gen-upbdefs",
|
65
|
+
srcs = [
|
66
|
+
"protoc-gen-upbdefs.cc",
|
67
|
+
],
|
68
|
+
copts = UPB_DEFAULT_CPPOPTS,
|
69
|
+
visibility = ["//visibility:public"],
|
70
|
+
deps = [
|
71
|
+
":common",
|
72
|
+
"@com_google_absl//absl/base:core_headers",
|
73
|
+
"@com_google_absl//absl/container:flat_hash_map",
|
74
|
+
"@com_google_absl//absl/strings",
|
75
|
+
"@com_google_protobuf//:protobuf",
|
76
|
+
"@com_google_protobuf//:protoc_lib",
|
77
|
+
],
|
78
|
+
)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
// Copyright (c) 2009-2021, Google LLC
|
2
|
+
// All rights reserved.
|
3
|
+
//
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
5
|
+
// modification, are permitted provided that the following conditions are met:
|
6
|
+
// * Redistributions of source code must retain the above copyright
|
7
|
+
// notice, this list of conditions and the following disclaimer.
|
8
|
+
// * Redistributions in binary form must reproduce the above copyright
|
9
|
+
// notice, this list of conditions and the following disclaimer in the
|
10
|
+
// documentation and/or other materials provided with the distribution.
|
11
|
+
// * Neither the name of Google LLC nor the
|
12
|
+
// names of its contributors may be used to endorse or promote products
|
13
|
+
// derived from this software without specific prior written permission.
|
14
|
+
//
|
15
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16
|
+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
+
// ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
19
|
+
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
26
|
+
#include "upbc/common.h"
|
27
|
+
|
28
|
+
#include "absl/strings/str_replace.h"
|
29
|
+
|
30
|
+
namespace upbc {
|
31
|
+
namespace {
|
32
|
+
|
33
|
+
namespace protobuf = ::google::protobuf;
|
34
|
+
|
35
|
+
} // namespace
|
36
|
+
|
37
|
+
std::string StripExtension(absl::string_view fname) {
|
38
|
+
size_t lastdot = fname.find_last_of('.');
|
39
|
+
if (lastdot == std::string::npos) {
|
40
|
+
return std::string(fname);
|
41
|
+
}
|
42
|
+
return std::string(fname.substr(0, lastdot));
|
43
|
+
}
|
44
|
+
|
45
|
+
std::string ToCIdent(absl::string_view str) {
|
46
|
+
return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}});
|
47
|
+
}
|
48
|
+
|
49
|
+
std::string ToPreproc(absl::string_view str) {
|
50
|
+
return absl::AsciiStrToUpper(ToCIdent(str));
|
51
|
+
}
|
52
|
+
|
53
|
+
void EmitFileWarning(const protobuf::FileDescriptor* file, Output& output) {
|
54
|
+
output(
|
55
|
+
"/* This file was generated by upbc (the upb compiler) from the input\n"
|
56
|
+
" * file:\n"
|
57
|
+
" *\n"
|
58
|
+
" * $0\n"
|
59
|
+
" *\n"
|
60
|
+
" * Do not edit -- your changes will be discarded when the file is\n"
|
61
|
+
" * regenerated. */\n\n",
|
62
|
+
file->name());
|
63
|
+
}
|
64
|
+
|
65
|
+
std::string MessageName(const protobuf::Descriptor* descriptor) {
|
66
|
+
return ToCIdent(descriptor->full_name());
|
67
|
+
}
|
68
|
+
|
69
|
+
std::string FileLayoutName(const google::protobuf::FileDescriptor* file) {
|
70
|
+
return ToCIdent(file->name()) + "_upb_file_layout";
|
71
|
+
}
|
72
|
+
|
73
|
+
std::string HeaderFilename(const google::protobuf::FileDescriptor* file) {
|
74
|
+
return StripExtension(file->name()) + ".upb.h";
|
75
|
+
}
|
76
|
+
|
77
|
+
} // namespace upbc
|
@@ -0,0 +1,112 @@
|
|
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 UPBC_COMMON_H
|
29
|
+
#define UPBC_COMMON_H
|
30
|
+
|
31
|
+
#include <vector>
|
32
|
+
|
33
|
+
#include "absl/strings/str_replace.h"
|
34
|
+
#include "absl/strings/substitute.h"
|
35
|
+
#include "google/protobuf/descriptor.h"
|
36
|
+
#include "google/protobuf/io/zero_copy_stream.h"
|
37
|
+
|
38
|
+
namespace upbc {
|
39
|
+
|
40
|
+
class Output {
|
41
|
+
public:
|
42
|
+
Output(google::protobuf::io::ZeroCopyOutputStream* stream)
|
43
|
+
: stream_(stream) {}
|
44
|
+
~Output() { stream_->BackUp((int)size_); }
|
45
|
+
|
46
|
+
template <class... Arg>
|
47
|
+
void operator()(absl::string_view format, const Arg&... arg) {
|
48
|
+
Write(absl::Substitute(format, arg...));
|
49
|
+
}
|
50
|
+
|
51
|
+
private:
|
52
|
+
void Write(absl::string_view data) {
|
53
|
+
std::string stripped;
|
54
|
+
if (absl::StartsWith(data, "\n ")) {
|
55
|
+
size_t indent = data.substr(1).find_first_not_of(' ');
|
56
|
+
if (indent != absl::string_view::npos) {
|
57
|
+
// Remove indentation from all lines.
|
58
|
+
auto line_prefix = data.substr(0, indent + 1);
|
59
|
+
// The final line has an extra newline and is indented two less, eg.
|
60
|
+
// R"cc(
|
61
|
+
// UPB_INLINE $0 $1_$2(const $1 *msg) {
|
62
|
+
// return $1_has_$2(msg) ? *UPB_PTR_AT(msg, $3, $0) : $4;
|
63
|
+
// }
|
64
|
+
// )cc",
|
65
|
+
std::string last_line_prefix = std::string(line_prefix);
|
66
|
+
last_line_prefix.resize(last_line_prefix.size() - 2);
|
67
|
+
data.remove_prefix(line_prefix.size());
|
68
|
+
stripped = absl::StrReplaceAll(
|
69
|
+
data, {{line_prefix, "\n"}, {last_line_prefix, "\n"}});
|
70
|
+
data = stripped;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
while (!data.empty()) {
|
74
|
+
RefreshOutput();
|
75
|
+
size_t to_write = std::min(data.size(), size_);
|
76
|
+
memcpy(ptr_, data.data(), to_write);
|
77
|
+
data.remove_prefix(to_write);
|
78
|
+
ptr_ += to_write;
|
79
|
+
size_ -= to_write;
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
void RefreshOutput() {
|
84
|
+
while (size_ == 0) {
|
85
|
+
void* ptr;
|
86
|
+
int size;
|
87
|
+
if (!stream_->Next(&ptr, &size)) {
|
88
|
+
fprintf(stderr, "upbc: Failed to write to to output\n");
|
89
|
+
abort();
|
90
|
+
}
|
91
|
+
ptr_ = static_cast<char*>(ptr);
|
92
|
+
size_ = size;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
google::protobuf::io::ZeroCopyOutputStream* stream_;
|
97
|
+
char* ptr_ = nullptr;
|
98
|
+
size_t size_ = 0;
|
99
|
+
};
|
100
|
+
|
101
|
+
std::string StripExtension(absl::string_view fname);
|
102
|
+
std::string ToCIdent(absl::string_view str);
|
103
|
+
std::string ToPreproc(absl::string_view str);
|
104
|
+
void EmitFileWarning(const google::protobuf::FileDescriptor* file,
|
105
|
+
Output& output);
|
106
|
+
std::string MessageName(const google::protobuf::Descriptor* descriptor);
|
107
|
+
std::string FileLayoutName(const google::protobuf::FileDescriptor* file);
|
108
|
+
std::string HeaderFilename(const google::protobuf::FileDescriptor* file);
|
109
|
+
|
110
|
+
} // namespace upbc
|
111
|
+
|
112
|
+
#endif // UPBC_COMMON_H
|