18#include "absl/strings/str_cat.h"
19#include "google/protobuf/descriptor.h"
20#include "google/protobuf/message.h"
21#include "google/protobuf/text_format.h"
26using ::google::protobuf::Descriptor;
27using ::google::protobuf::FieldDescriptor;
28using ::google::protobuf::Reflection;
29using ::google::protobuf::TextFormat;
31void WriteFullProtocolMessage(
const google::protobuf::Message&
message,
32 int indent_level, std::string* out) {
33 std::string temp_string;
34 const std::string
indent(indent_level * 2,
' ');
35 const Descriptor* desc =
message.GetDescriptor();
36 const Reflection* refl =
message.GetReflection();
37 for (
int i = 0;
i < desc->field_count(); ++
i) {
38 const FieldDescriptor* fd = desc->field(i);
39 const bool repeated = fd->is_repeated();
40 const int start = repeated ? 0 : -1;
41 const int limit = repeated ? refl->FieldSize(
message, fd) : 0;
42 for (
int j =
start; j < limit; ++j) {
43 absl::StrAppend(out,
indent, fd->name());
44 if (fd->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
45 absl::StrAppend(out,
" {\n");
46 const google::protobuf::Message& nested_message =
47 repeated ? refl->GetRepeatedMessage(
message, fd, j)
48 : refl->GetMessage(
message, fd);
49 WriteFullProtocolMessage(nested_message, indent_level + 1, out);
50 absl::StrAppend(out,
indent,
"}\n");
52 TextFormat::PrintFieldValueToString(
message, fd, j, &temp_string);
53 absl::StrAppend(out,
": ", temp_string,
"\n");
61 const google::protobuf::Message&
message,
int indent_level) {
62 std::string message_str;
63 WriteFullProtocolMessage(
message, indent_level, &message_str);
In SWIG mode, we don't want anything besides these top-level includes.
std::string FullProtocolMessageAsString(const google::protobuf::Message &message, int indent_level)