Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 513015917
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Feb 28, 2023
1 parent d27df92 commit 7cc46f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 3 additions & 16 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -415,6 +416,7 @@ cc_library(
"metadata.h",
"reflection.h",
"reflection_internal.h",
"reflection_mode.h",
"reflection_ops.h",
"service.h",
"text_format.h",
Expand Down Expand Up @@ -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",
],
Expand Down
13 changes: 13 additions & 0 deletions src/google/protobuf/text_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -74,6 +75,9 @@
namespace google {
namespace protobuf {

using internal::ReflectionMode;
using internal::ScopedReflectionMode;

namespace {

inline bool IsHexNumber(const std::string& str) {
Expand Down Expand Up @@ -103,6 +107,8 @@ PROTOBUF_EXPORT std::atomic<bool> 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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -171,6 +181,9 @@ namespace internal {

void PerformAbslStringify(const Message& message,
absl::FunctionRef<void(absl::string_view)> 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);
Expand Down

0 comments on commit 7cc46f5

Please sign in to comment.