summaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-07-03 12:45:36 +0100
committerJon Skeet <jonskeet@google.com>2015-07-10 11:42:56 +0100
commit5b9288e47d7add219717d472aa95a5cfe1141ac9 (patch)
tree4c5013e008bde3b0425d61efd2c85f80fbb6afb8 /src/google/protobuf/compiler
parentf8c151f21e821371c55d1cd02b89ac1b8f50460f (diff)
downloadprotobuf-javalite-5b9288e47d7add219717d472aa95a5cfe1141ac9.tar.gz
Use the new JsonFormatter to implement ToString on generated messages.
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_field_base.h1
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_map_field.cc7
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_message.cc5
3 files changed, 7 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h
index 349d835b..bffa2062 100644
--- a/src/google/protobuf/compiler/csharp/csharp_field_base.h
+++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h
@@ -58,6 +58,7 @@ class FieldGeneratorBase : public SourceGeneratorBase {
virtual void WriteHash(io::Printer* printer) = 0;
virtual void WriteEquals(io::Printer* printer) = 0;
+ // Currently unused, as we use reflection to generate JSON
virtual void WriteToString(io::Printer* printer) = 0;
protected:
diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc
index cb7ce5f0..32c05232 100644
--- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc
@@ -117,12 +117,9 @@ void MapFieldGenerator::WriteEquals(io::Printer* printer) {
variables_,
"if (!$property_name$.Equals(other.$property_name$)) return false;\n");
}
+
void MapFieldGenerator::WriteToString(io::Printer* printer) {
- /*
- variables_["field_name"] = GetFieldName(descriptor_);
- printer->Print(
- variables_,
- "PrintField(\"$field_name$\", has$property_name$, $name$_, writer);\n");*/
+ // TODO: If we ever actually use ToString, we'll need to impleme this...
}
void MapFieldGenerator::GenerateCloningCode(io::Printer* printer) {
diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc
index 13544b26..ac135951 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message.cc
@@ -429,7 +429,10 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
printer->Outdent();
printer->Print("}\n\n");
- // TODO(jonskeet): ToString.
+ printer->Print(
+ "public override string ToString() {\n"
+ " return pb::JsonFormatter.Default.Format(this);\n"
+ "}\n\n");
}
void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer) {