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,472 @@
|
|
|
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/text_encode.h"
|
|
29
|
+
|
|
30
|
+
#include <ctype.h>
|
|
31
|
+
#include <float.h>
|
|
32
|
+
#include <inttypes.h>
|
|
33
|
+
#include <stdarg.h>
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#include <string.h>
|
|
36
|
+
|
|
37
|
+
#include "upb/reflection.h"
|
|
38
|
+
#include "upb/upb_internal.h"
|
|
39
|
+
|
|
40
|
+
// Must be last.
|
|
41
|
+
#include "upb/port_def.inc"
|
|
42
|
+
|
|
43
|
+
typedef struct {
|
|
44
|
+
char *buf, *ptr, *end;
|
|
45
|
+
size_t overflow;
|
|
46
|
+
int indent_depth;
|
|
47
|
+
int options;
|
|
48
|
+
const upb_DefPool* ext_pool;
|
|
49
|
+
_upb_mapsorter sorter;
|
|
50
|
+
} txtenc;
|
|
51
|
+
|
|
52
|
+
static void txtenc_msg(txtenc* e, const upb_Message* msg,
|
|
53
|
+
const upb_MessageDef* m);
|
|
54
|
+
|
|
55
|
+
static void txtenc_putbytes(txtenc* e, const void* data, size_t len) {
|
|
56
|
+
size_t have = e->end - e->ptr;
|
|
57
|
+
if (UPB_LIKELY(have >= len)) {
|
|
58
|
+
memcpy(e->ptr, data, len);
|
|
59
|
+
e->ptr += len;
|
|
60
|
+
} else {
|
|
61
|
+
if (have) {
|
|
62
|
+
memcpy(e->ptr, data, have);
|
|
63
|
+
e->ptr += have;
|
|
64
|
+
}
|
|
65
|
+
e->overflow += (len - have);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static void txtenc_putstr(txtenc* e, const char* str) {
|
|
70
|
+
txtenc_putbytes(e, str, strlen(str));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static void txtenc_printf(txtenc* e, const char* fmt, ...) {
|
|
74
|
+
size_t n;
|
|
75
|
+
size_t have = e->end - e->ptr;
|
|
76
|
+
va_list args;
|
|
77
|
+
|
|
78
|
+
va_start(args, fmt);
|
|
79
|
+
n = vsnprintf(e->ptr, have, fmt, args);
|
|
80
|
+
va_end(args);
|
|
81
|
+
|
|
82
|
+
if (UPB_LIKELY(have > n)) {
|
|
83
|
+
e->ptr += n;
|
|
84
|
+
} else {
|
|
85
|
+
e->ptr = UPB_PTRADD(e->ptr, have);
|
|
86
|
+
e->overflow += (n - have);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static void txtenc_indent(txtenc* e) {
|
|
91
|
+
if ((e->options & UPB_TXTENC_SINGLELINE) == 0) {
|
|
92
|
+
int i = e->indent_depth;
|
|
93
|
+
while (i-- > 0) {
|
|
94
|
+
txtenc_putstr(e, " ");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static void txtenc_endfield(txtenc* e) {
|
|
100
|
+
if (e->options & UPB_TXTENC_SINGLELINE) {
|
|
101
|
+
txtenc_putstr(e, " ");
|
|
102
|
+
} else {
|
|
103
|
+
txtenc_putstr(e, "\n");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static void txtenc_enum(int32_t val, const upb_FieldDef* f, txtenc* e) {
|
|
108
|
+
const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f);
|
|
109
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e_def, val);
|
|
110
|
+
|
|
111
|
+
if (ev) {
|
|
112
|
+
txtenc_printf(e, "%s", upb_EnumValueDef_Name(ev));
|
|
113
|
+
} else {
|
|
114
|
+
txtenc_printf(e, "%" PRId32, val);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static void txtenc_string(txtenc* e, upb_StringView str, bool bytes) {
|
|
119
|
+
const char* ptr = str.data;
|
|
120
|
+
const char* end = ptr + str.size;
|
|
121
|
+
txtenc_putstr(e, "\"");
|
|
122
|
+
|
|
123
|
+
while (ptr < end) {
|
|
124
|
+
switch (*ptr) {
|
|
125
|
+
case '\n':
|
|
126
|
+
txtenc_putstr(e, "\\n");
|
|
127
|
+
break;
|
|
128
|
+
case '\r':
|
|
129
|
+
txtenc_putstr(e, "\\r");
|
|
130
|
+
break;
|
|
131
|
+
case '\t':
|
|
132
|
+
txtenc_putstr(e, "\\t");
|
|
133
|
+
break;
|
|
134
|
+
case '\"':
|
|
135
|
+
txtenc_putstr(e, "\\\"");
|
|
136
|
+
break;
|
|
137
|
+
case '\'':
|
|
138
|
+
txtenc_putstr(e, "\\'");
|
|
139
|
+
break;
|
|
140
|
+
case '\\':
|
|
141
|
+
txtenc_putstr(e, "\\\\");
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
if ((bytes || (uint8_t)*ptr < 0x80) && !isprint(*ptr)) {
|
|
145
|
+
txtenc_printf(e, "\\%03o", (int)(uint8_t)*ptr);
|
|
146
|
+
} else {
|
|
147
|
+
txtenc_putbytes(e, ptr, 1);
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
ptr++;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
txtenc_putstr(e, "\"");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static void txtenc_field(txtenc* e, upb_MessageValue val,
|
|
158
|
+
const upb_FieldDef* f) {
|
|
159
|
+
txtenc_indent(e);
|
|
160
|
+
upb_CType type = upb_FieldDef_CType(f);
|
|
161
|
+
const char* name = upb_FieldDef_Name(f);
|
|
162
|
+
|
|
163
|
+
if (type == kUpb_CType_Message) {
|
|
164
|
+
txtenc_printf(e, "%s {", name);
|
|
165
|
+
txtenc_endfield(e);
|
|
166
|
+
e->indent_depth++;
|
|
167
|
+
txtenc_msg(e, val.msg_val, upb_FieldDef_MessageSubDef(f));
|
|
168
|
+
e->indent_depth--;
|
|
169
|
+
txtenc_indent(e);
|
|
170
|
+
txtenc_putstr(e, "}");
|
|
171
|
+
txtenc_endfield(e);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
txtenc_printf(e, "%s: ", name);
|
|
176
|
+
|
|
177
|
+
switch (type) {
|
|
178
|
+
case kUpb_CType_Bool:
|
|
179
|
+
txtenc_putstr(e, val.bool_val ? "true" : "false");
|
|
180
|
+
break;
|
|
181
|
+
case kUpb_CType_Float: {
|
|
182
|
+
char buf[32];
|
|
183
|
+
_upb_EncodeRoundTripFloat(val.float_val, buf, sizeof(buf));
|
|
184
|
+
txtenc_putstr(e, buf);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case kUpb_CType_Double: {
|
|
188
|
+
char buf[32];
|
|
189
|
+
_upb_EncodeRoundTripDouble(val.double_val, buf, sizeof(buf));
|
|
190
|
+
txtenc_putstr(e, buf);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case kUpb_CType_Int32:
|
|
194
|
+
txtenc_printf(e, "%" PRId32, val.int32_val);
|
|
195
|
+
break;
|
|
196
|
+
case kUpb_CType_UInt32:
|
|
197
|
+
txtenc_printf(e, "%" PRIu32, val.uint32_val);
|
|
198
|
+
break;
|
|
199
|
+
case kUpb_CType_Int64:
|
|
200
|
+
txtenc_printf(e, "%" PRId64, val.int64_val);
|
|
201
|
+
break;
|
|
202
|
+
case kUpb_CType_UInt64:
|
|
203
|
+
txtenc_printf(e, "%" PRIu64, val.uint64_val);
|
|
204
|
+
break;
|
|
205
|
+
case kUpb_CType_String:
|
|
206
|
+
txtenc_string(e, val.str_val, false);
|
|
207
|
+
break;
|
|
208
|
+
case kUpb_CType_Bytes:
|
|
209
|
+
txtenc_string(e, val.str_val, true);
|
|
210
|
+
break;
|
|
211
|
+
case kUpb_CType_Enum:
|
|
212
|
+
txtenc_enum(val.int32_val, f, e);
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
UPB_UNREACHABLE();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
txtenc_endfield(e);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/*
|
|
222
|
+
* Arrays print as simple repeated elements, eg.
|
|
223
|
+
*
|
|
224
|
+
* foo_field: 1
|
|
225
|
+
* foo_field: 2
|
|
226
|
+
* foo_field: 3
|
|
227
|
+
*/
|
|
228
|
+
static void txtenc_array(txtenc* e, const upb_Array* arr,
|
|
229
|
+
const upb_FieldDef* f) {
|
|
230
|
+
size_t i;
|
|
231
|
+
size_t size = upb_Array_Size(arr);
|
|
232
|
+
|
|
233
|
+
for (i = 0; i < size; i++) {
|
|
234
|
+
txtenc_field(e, upb_Array_Get(arr, i), f);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static void txtenc_mapentry(txtenc* e, upb_MessageValue key,
|
|
239
|
+
upb_MessageValue val, const upb_FieldDef* f) {
|
|
240
|
+
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
|
|
241
|
+
const upb_FieldDef* key_f = upb_MessageDef_Field(entry, 0);
|
|
242
|
+
const upb_FieldDef* val_f = upb_MessageDef_Field(entry, 1);
|
|
243
|
+
txtenc_indent(e);
|
|
244
|
+
txtenc_printf(e, "%s {", upb_FieldDef_Name(f));
|
|
245
|
+
txtenc_endfield(e);
|
|
246
|
+
e->indent_depth++;
|
|
247
|
+
|
|
248
|
+
txtenc_field(e, key, key_f);
|
|
249
|
+
txtenc_field(e, val, val_f);
|
|
250
|
+
|
|
251
|
+
e->indent_depth--;
|
|
252
|
+
txtenc_indent(e);
|
|
253
|
+
txtenc_putstr(e, "}");
|
|
254
|
+
txtenc_endfield(e);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Maps print as messages of key/value, etc.
|
|
259
|
+
*
|
|
260
|
+
* foo_map: {
|
|
261
|
+
* key: "abc"
|
|
262
|
+
* value: 123
|
|
263
|
+
* }
|
|
264
|
+
* foo_map: {
|
|
265
|
+
* key: "def"
|
|
266
|
+
* value: 456
|
|
267
|
+
* }
|
|
268
|
+
*/
|
|
269
|
+
static void txtenc_map(txtenc* e, const upb_Map* map, const upb_FieldDef* f) {
|
|
270
|
+
if (e->options & UPB_TXTENC_NOSORT) {
|
|
271
|
+
size_t iter = kUpb_Map_Begin;
|
|
272
|
+
while (upb_MapIterator_Next(map, &iter)) {
|
|
273
|
+
upb_MessageValue key = upb_MapIterator_Key(map, iter);
|
|
274
|
+
upb_MessageValue val = upb_MapIterator_Value(map, iter);
|
|
275
|
+
txtenc_mapentry(e, key, val, f);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
|
|
279
|
+
const upb_FieldDef* key_f = upb_MessageDef_Field(entry, 0);
|
|
280
|
+
_upb_sortedmap sorted;
|
|
281
|
+
upb_MapEntry ent;
|
|
282
|
+
|
|
283
|
+
_upb_mapsorter_pushmap(&e->sorter, upb_FieldDef_Type(key_f), map, &sorted);
|
|
284
|
+
while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) {
|
|
285
|
+
upb_MessageValue key, val;
|
|
286
|
+
memcpy(&key, &ent.k, sizeof(key));
|
|
287
|
+
memcpy(&val, &ent.v, sizeof(val));
|
|
288
|
+
txtenc_mapentry(e, key, val, f);
|
|
289
|
+
}
|
|
290
|
+
_upb_mapsorter_popmap(&e->sorter, &sorted);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#define CHK(x) \
|
|
295
|
+
do { \
|
|
296
|
+
if (!(x)) { \
|
|
297
|
+
return false; \
|
|
298
|
+
} \
|
|
299
|
+
} while (0)
|
|
300
|
+
|
|
301
|
+
static const char* txtenc_parsevarint(const char* ptr, const char* limit,
|
|
302
|
+
uint64_t* val) {
|
|
303
|
+
uint8_t byte;
|
|
304
|
+
int bitpos = 0;
|
|
305
|
+
*val = 0;
|
|
306
|
+
|
|
307
|
+
do {
|
|
308
|
+
CHK(bitpos < 70 && ptr < limit);
|
|
309
|
+
byte = *ptr;
|
|
310
|
+
*val |= (uint64_t)(byte & 0x7F) << bitpos;
|
|
311
|
+
ptr++;
|
|
312
|
+
bitpos += 7;
|
|
313
|
+
} while (byte & 0x80);
|
|
314
|
+
|
|
315
|
+
return ptr;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/*
|
|
319
|
+
* Unknown fields are printed by number.
|
|
320
|
+
*
|
|
321
|
+
* 1001: 123
|
|
322
|
+
* 1002: "hello"
|
|
323
|
+
* 1006: 0xdeadbeef
|
|
324
|
+
* 1003: {
|
|
325
|
+
* 1: 111
|
|
326
|
+
* }
|
|
327
|
+
*/
|
|
328
|
+
static const char* txtenc_unknown(txtenc* e, const char* ptr, const char* end,
|
|
329
|
+
int groupnum) {
|
|
330
|
+
while (ptr < end) {
|
|
331
|
+
uint64_t tag_64;
|
|
332
|
+
uint32_t tag;
|
|
333
|
+
CHK(ptr = txtenc_parsevarint(ptr, end, &tag_64));
|
|
334
|
+
CHK(tag_64 < UINT32_MAX);
|
|
335
|
+
tag = (uint32_t)tag_64;
|
|
336
|
+
|
|
337
|
+
if ((tag & 7) == kUpb_WireType_EndGroup) {
|
|
338
|
+
CHK((tag >> 3) == (uint32_t)groupnum);
|
|
339
|
+
return ptr;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
txtenc_indent(e);
|
|
343
|
+
txtenc_printf(e, "%d: ", (int)(tag >> 3));
|
|
344
|
+
|
|
345
|
+
switch (tag & 7) {
|
|
346
|
+
case kUpb_WireType_Varint: {
|
|
347
|
+
uint64_t val;
|
|
348
|
+
CHK(ptr = txtenc_parsevarint(ptr, end, &val));
|
|
349
|
+
txtenc_printf(e, "%" PRIu64, val);
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case kUpb_WireType_32Bit: {
|
|
353
|
+
uint32_t val;
|
|
354
|
+
CHK(end - ptr >= 4);
|
|
355
|
+
memcpy(&val, ptr, 4);
|
|
356
|
+
ptr += 4;
|
|
357
|
+
txtenc_printf(e, "0x%08" PRIu32, val);
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case kUpb_WireType_64Bit: {
|
|
361
|
+
uint64_t val;
|
|
362
|
+
CHK(end - ptr >= 8);
|
|
363
|
+
memcpy(&val, ptr, 8);
|
|
364
|
+
ptr += 8;
|
|
365
|
+
txtenc_printf(e, "0x%016" PRIu64, val);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case kUpb_WireType_Delimited: {
|
|
369
|
+
uint64_t len;
|
|
370
|
+
size_t avail = end - ptr;
|
|
371
|
+
char* start = e->ptr;
|
|
372
|
+
size_t start_overflow = e->overflow;
|
|
373
|
+
CHK(ptr = txtenc_parsevarint(ptr, end, &len));
|
|
374
|
+
CHK(avail >= len);
|
|
375
|
+
|
|
376
|
+
/* Speculatively try to parse as message. */
|
|
377
|
+
txtenc_putstr(e, "{");
|
|
378
|
+
txtenc_endfield(e);
|
|
379
|
+
e->indent_depth++;
|
|
380
|
+
if (txtenc_unknown(e, ptr, end, -1)) {
|
|
381
|
+
e->indent_depth--;
|
|
382
|
+
txtenc_indent(e);
|
|
383
|
+
txtenc_putstr(e, "}");
|
|
384
|
+
} else {
|
|
385
|
+
/* Didn't work out, print as raw bytes. */
|
|
386
|
+
upb_StringView str;
|
|
387
|
+
e->indent_depth--;
|
|
388
|
+
e->ptr = start;
|
|
389
|
+
e->overflow = start_overflow;
|
|
390
|
+
str.data = ptr;
|
|
391
|
+
str.size = len;
|
|
392
|
+
txtenc_string(e, str, true);
|
|
393
|
+
}
|
|
394
|
+
ptr += len;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
case kUpb_WireType_StartGroup:
|
|
398
|
+
txtenc_putstr(e, "{");
|
|
399
|
+
txtenc_endfield(e);
|
|
400
|
+
e->indent_depth++;
|
|
401
|
+
CHK(ptr = txtenc_unknown(e, ptr, end, tag >> 3));
|
|
402
|
+
e->indent_depth--;
|
|
403
|
+
txtenc_indent(e);
|
|
404
|
+
txtenc_putstr(e, "}");
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
txtenc_endfield(e);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return groupnum == -1 ? ptr : NULL;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
#undef CHK
|
|
414
|
+
|
|
415
|
+
static void txtenc_msg(txtenc* e, const upb_Message* msg,
|
|
416
|
+
const upb_MessageDef* m) {
|
|
417
|
+
size_t iter = kUpb_Message_Begin;
|
|
418
|
+
const upb_FieldDef* f;
|
|
419
|
+
upb_MessageValue val;
|
|
420
|
+
|
|
421
|
+
while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) {
|
|
422
|
+
if (upb_FieldDef_IsMap(f)) {
|
|
423
|
+
txtenc_map(e, val.map_val, f);
|
|
424
|
+
} else if (upb_FieldDef_IsRepeated(f)) {
|
|
425
|
+
txtenc_array(e, val.array_val, f);
|
|
426
|
+
} else {
|
|
427
|
+
txtenc_field(e, val, f);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if ((e->options & UPB_TXTENC_SKIPUNKNOWN) == 0) {
|
|
432
|
+
size_t len;
|
|
433
|
+
const char* ptr = upb_Message_GetUnknown(msg, &len);
|
|
434
|
+
char* start = e->ptr;
|
|
435
|
+
if (ptr) {
|
|
436
|
+
if (!txtenc_unknown(e, ptr, ptr + len, -1)) {
|
|
437
|
+
/* Unknown failed to parse, back up and don't print it at all. */
|
|
438
|
+
e->ptr = start;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
size_t txtenc_nullz(txtenc* e, size_t size) {
|
|
445
|
+
size_t ret = e->ptr - e->buf + e->overflow;
|
|
446
|
+
|
|
447
|
+
if (size > 0) {
|
|
448
|
+
if (e->ptr == e->end) e->ptr--;
|
|
449
|
+
*e->ptr = '\0';
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return ret;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m,
|
|
456
|
+
const upb_DefPool* ext_pool, int options, char* buf,
|
|
457
|
+
size_t size) {
|
|
458
|
+
txtenc e;
|
|
459
|
+
|
|
460
|
+
e.buf = buf;
|
|
461
|
+
e.ptr = buf;
|
|
462
|
+
e.end = UPB_PTRADD(buf, size);
|
|
463
|
+
e.overflow = 0;
|
|
464
|
+
e.indent_depth = 0;
|
|
465
|
+
e.options = options;
|
|
466
|
+
e.ext_pool = ext_pool;
|
|
467
|
+
_upb_mapsorter_init(&e.sorter);
|
|
468
|
+
|
|
469
|
+
txtenc_msg(&e, msg, m);
|
|
470
|
+
_upb_mapsorter_destroy(&e.sorter);
|
|
471
|
+
return txtenc_nullz(&e, size);
|
|
472
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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_TEXTENCODE_H_
|
|
29
|
+
#define UPB_TEXTENCODE_H_
|
|
30
|
+
|
|
31
|
+
#include "upb/def.h"
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
extern "C" {
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
enum {
|
|
38
|
+
/* When set, prints everything on a single line. */
|
|
39
|
+
UPB_TXTENC_SINGLELINE = 1,
|
|
40
|
+
|
|
41
|
+
/* When set, unknown fields are not printed. */
|
|
42
|
+
UPB_TXTENC_SKIPUNKNOWN = 2,
|
|
43
|
+
|
|
44
|
+
/* When set, maps are *not* sorted (this avoids allocating tmp mem). */
|
|
45
|
+
UPB_TXTENC_NOSORT = 4
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/* Encodes the given |msg| to text format. The message's reflection is given in
|
|
49
|
+
* |m|. The symtab in |symtab| is used to find extensions (if NULL, extensions
|
|
50
|
+
* will not be printed).
|
|
51
|
+
*
|
|
52
|
+
* Output is placed in the given buffer, and always NULL-terminated. The output
|
|
53
|
+
* size (excluding NULL) is returned. This means that a return value >= |size|
|
|
54
|
+
* implies that the output was truncated. (These are the same semantics as
|
|
55
|
+
* snprintf()). */
|
|
56
|
+
size_t upb_TextEncode(const upb_Message* msg, const upb_MessageDef* m,
|
|
57
|
+
const upb_DefPool* ext_pool, int options, char* buf,
|
|
58
|
+
size_t size);
|
|
59
|
+
|
|
60
|
+
#ifdef __cplusplus
|
|
61
|
+
} /* extern "C" */
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
#endif /* UPB_TEXTENCODE_H_ */
|