diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index c4a1f15ce2..8287a6d416 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -39,6 +39,7 @@ #include #include "google/protobuf/stubs/logging.h" #include "absl/strings/match.h" +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "google/protobuf/arena_test_util.h" #include "google/protobuf/io/coded_stream.h" @@ -1171,6 +1172,7 @@ TYPED_TEST(LiteTest, DebugString) { EXPECT_NE(message1.DebugString(), message2.DebugString()); } + TYPED_TEST(LiteTest, EnumValueToName) { EXPECT_EQ("FOREIGN_LITE_FOO", protobuf_unittest::ForeignEnumLite_Name( protobuf_unittest::FOREIGN_LITE_FOO)); diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 6b056b803d..ced6d86bb8 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -222,6 +222,13 @@ class PROTOBUF_EXPORT MessageLite { // with Message. std::string Utf8DebugString() const { return DebugString(); } + // Implementation of the `AbslStringify` interface. This adds `DebugString()` + // to the sink. Do not rely on exact format. + template + friend void AbslStringify(Sink& sink, const google::protobuf::MessageLite& msg) { + sink.Append(msg.DebugString()); + } + // Parsing --------------------------------------------------------- // Methods for parsing in protocol buffer format. Most of these are // just simple wrappers around MergeFromCodedStream(). Clear() will be