ruby_memprofiler_pprof 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +7 -0
  2. data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
  3. data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
  4. data/ext/ruby_memprofiler_pprof/compat.c +182 -0
  5. data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
  6. data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
  7. data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
  8. data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
  9. data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
  10. data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
  11. data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
  12. data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
  13. data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
  14. data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
  15. data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
  16. data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
  17. data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
  18. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
  19. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
  20. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
  21. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
  22. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
  23. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
  24. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
  25. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
  26. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
  27. data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
  28. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
  29. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
  30. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
  31. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
  32. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
  33. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
  34. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
  35. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
  36. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
  37. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
  38. data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
  39. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
  40. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
  41. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
  42. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
  43. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
  44. data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
  45. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
  46. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
  47. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
  48. data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
  49. data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
  50. data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
  51. data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
  52. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
  53. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
  54. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
  55. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
  56. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
  57. data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
  58. data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
  59. data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
  60. data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
  61. data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
  62. data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
  63. data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
  64. data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
  65. data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
  66. data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
  67. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
  68. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
  69. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
  70. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
  71. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
  72. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
  73. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
  74. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
  75. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
  76. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
  77. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
  78. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
  79. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
  80. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
  81. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
  82. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
  83. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
  84. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
  85. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
  86. data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
  87. data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
  88. data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
  89. data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
  90. data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
  91. data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
  92. data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
  93. data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
  94. data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
  95. data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
  96. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
  97. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
  98. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
  99. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
  100. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
  101. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
  102. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
  103. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
  104. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
  105. data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
  106. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
  107. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
  108. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
  109. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
  110. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
  111. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
  112. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
  113. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
  114. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
  115. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
  116. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
  117. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
  118. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
  119. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
  120. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
  121. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
  122. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
  123. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
  124. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
  125. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
  126. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
  127. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
  128. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
  129. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
  130. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
  131. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
  132. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
  133. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
  134. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
  135. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
  136. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
  137. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
  138. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
  139. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
  140. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
  141. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
  142. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
  143. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
  144. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
  145. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
  146. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
  147. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
  148. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
  149. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
  150. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
  151. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
  152. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
  153. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
  154. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
  155. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
  156. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
  157. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
  158. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
  159. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
  160. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
  161. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
  162. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
  163. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
  164. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
  165. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
  166. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
  167. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
  168. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
  169. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
  170. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
  171. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
  172. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
  173. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
  174. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
  175. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
  176. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
  177. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
  178. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
  179. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
  180. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
  181. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
  182. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
  183. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
  184. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
  185. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
  186. data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
  187. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
  188. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
  189. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
  190. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
  191. data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
  192. data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
  193. data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
  194. data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
  195. data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
  196. data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
  197. data/lib/ruby_memprofiler_pprof/version.rb +5 -0
  198. data/lib/ruby_memprofiler_pprof.rb +8 -0
  199. data/libexec/ruby_memprofiler_pprof_profile +16 -0
  200. metadata +257 -0
@@ -0,0 +1,438 @@
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
+ #ifndef UPB_DEF_HPP_
27
+ #define UPB_DEF_HPP_
28
+
29
+ #include <cstring>
30
+ #include <memory>
31
+ #include <string>
32
+ #include <vector>
33
+
34
+ #include "upb/def.h"
35
+ #include "upb/reflection.h"
36
+ #include "upb/upb.hpp"
37
+
38
+ namespace upb {
39
+
40
+ typedef upb_MessageValue MessageValue;
41
+
42
+ class EnumDefPtr;
43
+ class FileDefPtr;
44
+ class MessageDefPtr;
45
+ class OneofDefPtr;
46
+
47
+ // A upb::FieldDefPtr describes a single field in a message. It is most often
48
+ // found as a part of a upb_MessageDef, but can also stand alone to represent
49
+ // an extension.
50
+ class FieldDefPtr {
51
+ public:
52
+ FieldDefPtr() : ptr_(nullptr) {}
53
+ explicit FieldDefPtr(const upb_FieldDef* ptr) : ptr_(ptr) {}
54
+
55
+ const upb_FieldDef* ptr() const { return ptr_; }
56
+ explicit operator bool() const { return ptr_ != nullptr; }
57
+
58
+ typedef upb_CType Type;
59
+ typedef upb_Label Label;
60
+ typedef upb_FieldType DescriptorType;
61
+
62
+ const char* full_name() const { return upb_FieldDef_FullName(ptr_); }
63
+
64
+ Type type() const { return upb_FieldDef_CType(ptr_); }
65
+ Label label() const { return upb_FieldDef_Label(ptr_); }
66
+ const char* name() const { return upb_FieldDef_Name(ptr_); }
67
+ const char* json_name() const { return upb_FieldDef_JsonName(ptr_); }
68
+ uint32_t number() const { return upb_FieldDef_Number(ptr_); }
69
+ bool is_extension() const { return upb_FieldDef_IsExtension(ptr_); }
70
+
71
+ // For non-string, non-submessage fields, this indicates whether binary
72
+ // protobufs are encoded in packed or non-packed format.
73
+ //
74
+ // Note: this accessor reflects the fact that "packed" has different defaults
75
+ // depending on whether the proto is proto2 or proto3.
76
+ bool packed() const { return upb_FieldDef_IsPacked(ptr_); }
77
+
78
+ // An integer that can be used as an index into an array of fields for
79
+ // whatever message this field belongs to. Guaranteed to be less than
80
+ // f->containing_type()->field_count(). May only be accessed once the def has
81
+ // been finalized.
82
+ uint32_t index() const { return upb_FieldDef_Index(ptr_); }
83
+
84
+ // The MessageDef to which this field belongs.
85
+ //
86
+ // If this field has been added to a MessageDef, that message can be retrieved
87
+ // directly (this is always the case for frozen FieldDefs).
88
+ //
89
+ // If the field has not yet been added to a MessageDef, you can set the name
90
+ // of the containing type symbolically instead. This is mostly useful for
91
+ // extensions, where the extension is declared separately from the message.
92
+ MessageDefPtr containing_type() const;
93
+
94
+ // The OneofDef to which this field belongs, or NULL if this field is not part
95
+ // of a oneof.
96
+ OneofDefPtr containing_oneof() const;
97
+
98
+ // The field's type according to the enum in descriptor.proto. This is not
99
+ // the same as UPB_TYPE_*, because it distinguishes between (for example)
100
+ // INT32 and SINT32, whereas our "type" enum does not. This return of
101
+ // descriptor_type() is a function of type(), integer_format(), and
102
+ // is_tag_delimited().
103
+ DescriptorType descriptor_type() const { return upb_FieldDef_Type(ptr_); }
104
+
105
+ // Convenient field type tests.
106
+ bool IsSubMessage() const { return upb_FieldDef_IsSubMessage(ptr_); }
107
+ bool IsString() const { return upb_FieldDef_IsString(ptr_); }
108
+ bool IsSequence() const { return upb_FieldDef_IsRepeated(ptr_); }
109
+ bool IsPrimitive() const { return upb_FieldDef_IsPrimitive(ptr_); }
110
+ bool IsMap() const { return upb_FieldDef_IsMap(ptr_); }
111
+
112
+ MessageValue default_value() const { return upb_FieldDef_Default(ptr_); }
113
+
114
+ // Returns the enum or submessage def for this field, if any. The field's
115
+ // type must match (ie. you may only call enum_subdef() for fields where
116
+ // type() == kUpb_CType_Enum).
117
+ EnumDefPtr enum_subdef() const;
118
+ MessageDefPtr message_subdef() const;
119
+
120
+ private:
121
+ const upb_FieldDef* ptr_;
122
+ };
123
+
124
+ // Class that represents a oneof.
125
+ class OneofDefPtr {
126
+ public:
127
+ OneofDefPtr() : ptr_(nullptr) {}
128
+ explicit OneofDefPtr(const upb_OneofDef* ptr) : ptr_(ptr) {}
129
+
130
+ const upb_OneofDef* ptr() const { return ptr_; }
131
+ explicit operator bool() const { return ptr_ != nullptr; }
132
+
133
+ // Returns the MessageDef that contains this OneofDef.
134
+ MessageDefPtr containing_type() const;
135
+
136
+ // Returns the name of this oneof.
137
+ const char* name() const { return upb_OneofDef_Name(ptr_); }
138
+
139
+ // Returns the number of fields in the oneof.
140
+ int field_count() const { return upb_OneofDef_FieldCount(ptr_); }
141
+ FieldDefPtr field(int i) const {
142
+ return FieldDefPtr(upb_OneofDef_Field(ptr_, i));
143
+ }
144
+
145
+ // Looks up by name.
146
+ FieldDefPtr FindFieldByName(const char* name, size_t len) const {
147
+ return FieldDefPtr(upb_OneofDef_LookupNameWithSize(ptr_, name, len));
148
+ }
149
+ FieldDefPtr FindFieldByName(const char* name) const {
150
+ return FieldDefPtr(upb_OneofDef_LookupName(ptr_, name));
151
+ }
152
+
153
+ template <class T>
154
+ FieldDefPtr FindFieldByName(const T& str) const {
155
+ return FindFieldByName(str.c_str(), str.size());
156
+ }
157
+
158
+ // Looks up by tag number.
159
+ FieldDefPtr FindFieldByNumber(uint32_t num) const {
160
+ return FieldDefPtr(upb_OneofDef_LookupNumber(ptr_, num));
161
+ }
162
+
163
+ private:
164
+ const upb_OneofDef* ptr_;
165
+ };
166
+
167
+ // Structure that describes a single .proto message type.
168
+ class MessageDefPtr {
169
+ public:
170
+ MessageDefPtr() : ptr_(nullptr) {}
171
+ explicit MessageDefPtr(const upb_MessageDef* ptr) : ptr_(ptr) {}
172
+
173
+ const upb_MessageDef* ptr() const { return ptr_; }
174
+ explicit operator bool() const { return ptr_ != nullptr; }
175
+
176
+ FileDefPtr file() const;
177
+
178
+ const char* full_name() const { return upb_MessageDef_FullName(ptr_); }
179
+ const char* name() const { return upb_MessageDef_Name(ptr_); }
180
+
181
+ // The number of fields that belong to the MessageDef.
182
+ int field_count() const { return upb_MessageDef_FieldCount(ptr_); }
183
+ FieldDefPtr field(int i) const {
184
+ return FieldDefPtr(upb_MessageDef_Field(ptr_, i));
185
+ }
186
+
187
+ // The number of oneofs that belong to the MessageDef.
188
+ int oneof_count() const { return upb_MessageDef_OneofCount(ptr_); }
189
+ OneofDefPtr oneof(int i) const {
190
+ return OneofDefPtr(upb_MessageDef_Oneof(ptr_, i));
191
+ }
192
+
193
+ upb_Syntax syntax() const { return upb_MessageDef_Syntax(ptr_); }
194
+
195
+ // These return null pointers if the field is not found.
196
+ FieldDefPtr FindFieldByNumber(uint32_t number) const {
197
+ return FieldDefPtr(upb_MessageDef_FindFieldByNumber(ptr_, number));
198
+ }
199
+ FieldDefPtr FindFieldByName(const char* name, size_t len) const {
200
+ return FieldDefPtr(upb_MessageDef_FindFieldByNameWithSize(ptr_, name, len));
201
+ }
202
+ FieldDefPtr FindFieldByName(const char* name) const {
203
+ return FieldDefPtr(upb_MessageDef_FindFieldByName(ptr_, name));
204
+ }
205
+
206
+ template <class T>
207
+ FieldDefPtr FindFieldByName(const T& str) const {
208
+ return FindFieldByName(str.c_str(), str.size());
209
+ }
210
+
211
+ OneofDefPtr FindOneofByName(const char* name, size_t len) const {
212
+ return OneofDefPtr(upb_MessageDef_FindOneofByNameWithSize(ptr_, name, len));
213
+ }
214
+
215
+ OneofDefPtr FindOneofByName(const char* name) const {
216
+ return OneofDefPtr(upb_MessageDef_FindOneofByName(ptr_, name));
217
+ }
218
+
219
+ template <class T>
220
+ OneofDefPtr FindOneofByName(const T& str) const {
221
+ return FindOneofByName(str.c_str(), str.size());
222
+ }
223
+
224
+ // Is this message a map entry?
225
+ bool mapentry() const { return upb_MessageDef_IsMapEntry(ptr_); }
226
+
227
+ // Return the type of well known type message. kUpb_WellKnown_Unspecified for
228
+ // non-well-known message.
229
+ upb_WellKnown wellknowntype() const {
230
+ return upb_MessageDef_WellKnownType(ptr_);
231
+ }
232
+
233
+ private:
234
+ class FieldIter {
235
+ public:
236
+ explicit FieldIter(const upb_MessageDef* m, int i) : m_(m), i_(i) {}
237
+ void operator++() { i_++; }
238
+
239
+ FieldDefPtr operator*() {
240
+ return FieldDefPtr(upb_MessageDef_Field(m_, i_));
241
+ }
242
+ bool operator!=(const FieldIter& other) { return i_ != other.i_; }
243
+ bool operator==(const FieldIter& other) { return i_ == other.i_; }
244
+
245
+ private:
246
+ const upb_MessageDef* m_;
247
+ int i_;
248
+ };
249
+
250
+ class FieldAccessor {
251
+ public:
252
+ explicit FieldAccessor(const upb_MessageDef* md) : md_(md) {}
253
+ FieldIter begin() { return FieldIter(md_, 0); }
254
+ FieldIter end() { return FieldIter(md_, upb_MessageDef_FieldCount(md_)); }
255
+
256
+ private:
257
+ const upb_MessageDef* md_;
258
+ };
259
+
260
+ class OneofIter {
261
+ public:
262
+ explicit OneofIter(const upb_MessageDef* m, int i) : m_(m), i_(i) {}
263
+ void operator++() { i_++; }
264
+
265
+ OneofDefPtr operator*() {
266
+ return OneofDefPtr(upb_MessageDef_Oneof(m_, i_));
267
+ }
268
+ bool operator!=(const OneofIter& other) { return i_ != other.i_; }
269
+ bool operator==(const OneofIter& other) { return i_ == other.i_; }
270
+
271
+ private:
272
+ const upb_MessageDef* m_;
273
+ int i_;
274
+ };
275
+
276
+ class OneofAccessor {
277
+ public:
278
+ explicit OneofAccessor(const upb_MessageDef* md) : md_(md) {}
279
+ OneofIter begin() { return OneofIter(md_, 0); }
280
+ OneofIter end() { return OneofIter(md_, upb_MessageDef_OneofCount(md_)); }
281
+
282
+ private:
283
+ const upb_MessageDef* md_;
284
+ };
285
+
286
+ public:
287
+ FieldAccessor fields() const { return FieldAccessor(ptr()); }
288
+ OneofAccessor oneofs() const { return OneofAccessor(ptr()); }
289
+
290
+ private:
291
+ const upb_MessageDef* ptr_;
292
+ };
293
+
294
+ class EnumValDefPtr {
295
+ public:
296
+ EnumValDefPtr() : ptr_(nullptr) {}
297
+ explicit EnumValDefPtr(const upb_EnumValueDef* ptr) : ptr_(ptr) {}
298
+
299
+ int32_t number() const { return upb_EnumValueDef_Number(ptr_); }
300
+ const char* full_name() const { return upb_EnumValueDef_FullName(ptr_); }
301
+ const char* name() const { return upb_EnumValueDef_Name(ptr_); }
302
+
303
+ private:
304
+ const upb_EnumValueDef* ptr_;
305
+ };
306
+
307
+ class EnumDefPtr {
308
+ public:
309
+ EnumDefPtr() : ptr_(nullptr) {}
310
+ explicit EnumDefPtr(const upb_EnumDef* ptr) : ptr_(ptr) {}
311
+
312
+ const upb_EnumDef* ptr() const { return ptr_; }
313
+ explicit operator bool() const { return ptr_ != nullptr; }
314
+
315
+ const char* full_name() const { return upb_EnumDef_FullName(ptr_); }
316
+ const char* name() const { return upb_EnumDef_Name(ptr_); }
317
+
318
+ // The value that is used as the default when no field default is specified.
319
+ // If not set explicitly, the first value that was added will be used.
320
+ // The default value must be a member of the enum.
321
+ // Requires that value_count() > 0.
322
+ int32_t default_value() const { return upb_EnumDef_Default(ptr_); }
323
+
324
+ // Returns the number of values currently defined in the enum. Note that
325
+ // multiple names can refer to the same number, so this may be greater than
326
+ // the total number of unique numbers.
327
+ int value_count() const { return upb_EnumDef_ValueCount(ptr_); }
328
+
329
+ // Lookups from name to integer, returning true if found.
330
+ EnumValDefPtr FindValueByName(const char* name) const {
331
+ return EnumValDefPtr(upb_EnumDef_FindValueByName(ptr_, name));
332
+ }
333
+
334
+ // Finds the name corresponding to the given number, or NULL if none was
335
+ // found. If more than one name corresponds to this number, returns the
336
+ // first one that was added.
337
+ EnumValDefPtr FindValueByNumber(int32_t num) const {
338
+ return EnumValDefPtr(upb_EnumDef_FindValueByNumber(ptr_, num));
339
+ }
340
+
341
+ private:
342
+ const upb_EnumDef* ptr_;
343
+ };
344
+
345
+ // Class that represents a .proto file with some things defined in it.
346
+ //
347
+ // Many users won't care about FileDefs, but they are necessary if you want to
348
+ // read the values of file-level options.
349
+ class FileDefPtr {
350
+ public:
351
+ explicit FileDefPtr(const upb_FileDef* ptr) : ptr_(ptr) {}
352
+
353
+ const upb_FileDef* ptr() const { return ptr_; }
354
+ explicit operator bool() const { return ptr_ != nullptr; }
355
+
356
+ // Get/set name of the file (eg. "foo/bar.proto").
357
+ const char* name() const { return upb_FileDef_Name(ptr_); }
358
+
359
+ // Package name for definitions inside the file (eg. "foo.bar").
360
+ const char* package() const { return upb_FileDef_Package(ptr_); }
361
+
362
+ // Syntax for the file. Defaults to proto2.
363
+ upb_Syntax syntax() const { return upb_FileDef_Syntax(ptr_); }
364
+
365
+ // Get the list of dependencies from the file. These are returned in the
366
+ // order that they were added to the FileDefPtr.
367
+ int dependency_count() const { return upb_FileDef_DependencyCount(ptr_); }
368
+ const FileDefPtr dependency(int index) const {
369
+ return FileDefPtr(upb_FileDef_Dependency(ptr_, index));
370
+ }
371
+
372
+ private:
373
+ const upb_FileDef* ptr_;
374
+ };
375
+
376
+ // Non-const methods in upb::SymbolTable are NOT thread-safe.
377
+ class SymbolTable {
378
+ public:
379
+ SymbolTable() : ptr_(upb_DefPool_New(), upb_DefPool_Free) {}
380
+ explicit SymbolTable(upb_DefPool* s) : ptr_(s, upb_DefPool_Free) {}
381
+
382
+ const upb_DefPool* ptr() const { return ptr_.get(); }
383
+ upb_DefPool* ptr() { return ptr_.get(); }
384
+
385
+ // Finds an entry in the symbol table with this exact name. If not found,
386
+ // returns NULL.
387
+ MessageDefPtr FindMessageByName(const char* sym) const {
388
+ return MessageDefPtr(upb_DefPool_FindMessageByName(ptr_.get(), sym));
389
+ }
390
+
391
+ EnumDefPtr FindEnumByName(const char* sym) const {
392
+ return EnumDefPtr(upb_DefPool_FindEnumByName(ptr_.get(), sym));
393
+ }
394
+
395
+ FileDefPtr FindFileByName(const char* name) const {
396
+ return FileDefPtr(upb_DefPool_FindFileByName(ptr_.get(), name));
397
+ }
398
+
399
+ // TODO: iteration?
400
+
401
+ // Adds the given serialized FileDescriptorProto to the pool.
402
+ FileDefPtr AddFile(const google_protobuf_FileDescriptorProto* file_proto,
403
+ Status* status) {
404
+ return FileDefPtr(
405
+ upb_DefPool_AddFile(ptr_.get(), file_proto, status->ptr()));
406
+ }
407
+
408
+ private:
409
+ std::unique_ptr<upb_DefPool, decltype(&upb_DefPool_Free)> ptr_;
410
+ };
411
+
412
+ inline FileDefPtr MessageDefPtr::file() const {
413
+ return FileDefPtr(upb_MessageDef_File(ptr_));
414
+ }
415
+
416
+ inline MessageDefPtr FieldDefPtr::message_subdef() const {
417
+ return MessageDefPtr(upb_FieldDef_MessageSubDef(ptr_));
418
+ }
419
+
420
+ inline MessageDefPtr FieldDefPtr::containing_type() const {
421
+ return MessageDefPtr(upb_FieldDef_ContainingType(ptr_));
422
+ }
423
+
424
+ inline MessageDefPtr OneofDefPtr::containing_type() const {
425
+ return MessageDefPtr(upb_OneofDef_ContainingType(ptr_));
426
+ }
427
+
428
+ inline OneofDefPtr FieldDefPtr::containing_oneof() const {
429
+ return OneofDefPtr(upb_FieldDef_ContainingOneof(ptr_));
430
+ }
431
+
432
+ inline EnumDefPtr FieldDefPtr::enum_subdef() const {
433
+ return EnumDefPtr(upb_FieldDef_EnumSubDef(ptr_));
434
+ }
435
+
436
+ } // namespace upb
437
+
438
+ #endif // UPB_DEF_HPP_
@@ -0,0 +1 @@
1
+ syntax = "proto2";