From 7cc46f50de7bdf6fff20e47afa6dc9964f7c6411 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 28 Feb 2023 12:59:31 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 513015917 --- pkg/BUILD.bazel | 1 - src/google/protobuf/BUILD.bazel | 19 +++---------------- src/google/protobuf/text_format.cc | 13 +++++++++++++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 89a46bf4be1b..0970cceed1d2 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -362,7 +362,6 @@ cc_dist_library( "//src/google/protobuf:arena_align", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf:wkt_cc_proto", - "//src/google/protobuf:reflection_mode", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/json", "//src/google/protobuf/util:delimited_message_util", diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 90dbb7b33a73..cb2835b36d3a 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -392,6 +392,7 @@ cc_library( "generated_message_tctable_gen.cc", "map_field.cc", "message.cc", + "reflection_mode.cc", "reflection_ops.cc", "service.cc", "text_format.cc", @@ -415,6 +416,7 @@ cc_library( "metadata.h", "reflection.h", "reflection_internal.h", + "reflection_mode.h", "reflection_ops.h", "service.h", "text_format.h", @@ -1314,26 +1316,11 @@ cc_test( ], ) -cc_library( - name = "reflection_mode", - srcs = ["reflection_mode.cc"], - hdrs = ["reflection_mode.h"], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - ":port_def", - ":protobuf", - ], -) - cc_test( name = "reflection_mode_test", srcs = ["reflection_mode_test.cc"], deps = [ - ":reflection_mode", + ":protobuf_nowkt", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 57ff14f29290..ac199007faf7 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -64,6 +64,7 @@ #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/map_field.h" #include "google/protobuf/message.h" +#include "google/protobuf/reflection_mode.h" #include "google/protobuf/repeated_field.h" #include "google/protobuf/unknown_field_set.h" #include "google/protobuf/wire_format_lite.h" @@ -74,6 +75,9 @@ namespace google { namespace protobuf { +using internal::ReflectionMode; +using internal::ScopedReflectionMode; + namespace { inline bool IsHexNumber(const std::string& str) { @@ -103,6 +107,8 @@ PROTOBUF_EXPORT std::atomic enable_debug_text_format_marker; } // namespace internal std::string Message::DebugString() const { + // Indicate all scoped reflection calls are from DebugString function. + ScopedReflectionMode scope(ReflectionMode::kDebugString); std::string debug_string; TextFormat::Printer printer; @@ -122,6 +128,8 @@ std::string Message::DebugString() const { } std::string Message::ShortDebugString() const { + // Indicate all scoped reflection calls are from DebugString function. + ScopedReflectionMode scope(ReflectionMode::kDebugString); std::string debug_string; TextFormat::Printer printer; @@ -146,6 +154,8 @@ std::string Message::ShortDebugString() const { } std::string Message::Utf8DebugString() const { + // Indicate all scoped reflection calls are from DebugString function. + ScopedReflectionMode scope(ReflectionMode::kDebugString); std::string debug_string; TextFormat::Printer printer; @@ -171,6 +181,9 @@ namespace internal { void PerformAbslStringify(const Message& message, absl::FunctionRef append) { + // Indicate all scoped reflection calls are from DebugString function. + ScopedReflectionMode scope(ReflectionMode::kDebugString); + // TODO(b/249835002): consider using the single line version for short TextFormat::Printer printer; printer.SetExpandAny(true);