Implement AbslStringify for MessageLite

PiperOrigin-RevId: 499547257
pull/10789/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 9810724b24
commit d5fd41d2d4
  1. 2
      src/google/protobuf/lite_unittest.cc
  2. 7
      src/google/protobuf/message_lite.h

@ -39,6 +39,7 @@
#include <gtest/gtest.h>
#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));

@ -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 <typename Sink>
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

Loading…
Cancel
Save