Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
5b9288e4
Commit
5b9288e4
authored
Jul 03, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the new JsonFormatter to implement ToString on generated messages.
parent
f8c151f2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
143 additions
and
6 deletions
+143
-6
Addressbook.cs
csharp/src/AddressBook/Addressbook.cs
+12
-0
MapUnittestProto3.cs
.../src/ProtocolBuffers.Test/TestProtos/MapUnittestProto3.cs
+0
-0
UnittestImportProto3.cs
...c/ProtocolBuffers.Test/TestProtos/UnittestImportProto3.cs
+4
-0
UnittestImportPublicProto3.cs
...ocolBuffers.Test/TestProtos/UnittestImportPublicProto3.cs
+4
-0
UnittestIssues.cs
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs
+28
-0
UnittestProto3.cs
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs
+0
-0
DescriptorProtoFile.cs
...c/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
+88
-0
csharp_field_base.h
src/google/protobuf/compiler/csharp/csharp_field_base.h
+1
-0
csharp_map_field.cc
src/google/protobuf/compiler/csharp/csharp_map_field.cc
+2
-5
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+4
-1
No files found.
csharp/src/AddressBook/Addressbook.cs
View file @
5b9288e4
...
...
@@ -160,6 +160,10 @@ namespace Google.Protobuf.Examples.AddressBook {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -330,6 +334,10 @@ namespace Google.Protobuf.Examples.AddressBook {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Number
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -463,6 +471,10 @@ namespace Google.Protobuf.Examples.AddressBook {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
person_
.
WriteTo
(
output
,
_repeated_person_codec
);
}
...
...
csharp/src/ProtocolBuffers.Test/TestProtos/MapUnittestProto3.cs
View file @
5b9288e4
This diff is collapsed.
Click to expand it.
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestImportProto3.cs
View file @
5b9288e4
...
...
@@ -124,6 +124,10 @@ namespace Google.Protobuf.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
D
!=
0
)
{
output
.
WriteRawTag
(
8
);
...
...
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestImportPublicProto3.cs
View file @
5b9288e4
...
...
@@ -109,6 +109,10 @@ namespace Google.Protobuf.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
E
!=
0
)
{
output
.
WriteRawTag
(
8
);
...
...
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestIssues.cs
View file @
5b9288e4
...
...
@@ -148,6 +148,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
}
...
...
@@ -237,6 +241,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
}
...
...
@@ -326,6 +334,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
}
...
...
@@ -459,6 +471,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Value
!=
global
::
UnitTest
.
Issues
.
TestProtos
.
NegativeEnum
.
NEGATIVE_ENUM_ZERO
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -577,6 +593,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
}
...
...
@@ -746,6 +766,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
PrimitiveValue
!=
0
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -918,6 +942,10 @@ namespace UnitTest.Issues.TestProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Item
!=
0
)
{
output
.
WriteRawTag
(
8
);
...
...
csharp/src/ProtocolBuffers.Test/TestProtos/UnittestProto3.cs
View file @
5b9288e4
This diff is collapsed.
Click to expand it.
csharp/src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
View file @
5b9288e4
...
...
@@ -299,6 +299,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
file_
.
WriteTo
(
output
,
_repeated_file_codec
);
}
...
...
@@ -545,6 +549,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -889,6 +897,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -1094,6 +1106,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Start
!=
0
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -1236,6 +1252,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Start
!=
0
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -1475,6 +1495,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -1741,6 +1765,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -1882,6 +1910,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -2051,6 +2083,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -2226,6 +2262,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -2434,6 +2474,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Name
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -2806,6 +2850,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
JavaPackage
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -3173,6 +3221,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
MessageSetWireFormat
!=
false
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -3414,6 +3466,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Ctype
!=
global
::
Google
.
Protobuf
.
DescriptorProtos
.
FieldOptions
.
Types
.
CType
.
STRING
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -3649,6 +3705,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
AllowAlias
!=
false
)
{
output
.
WriteRawTag
(
16
);
...
...
@@ -3797,6 +3857,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Deprecated
!=
false
)
{
output
.
WriteRawTag
(
8
);
...
...
@@ -3931,6 +3995,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Deprecated
!=
false
)
{
output
.
WriteRawTag
(
136
,
2
);
...
...
@@ -4065,6 +4133,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
Deprecated
!=
false
)
{
output
.
WriteRawTag
(
136
,
2
);
...
...
@@ -4264,6 +4336,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
name_
.
WriteTo
(
output
,
_repeated_name_codec
);
if
(
IdentifierValue
.
Length
!=
0
)
{
...
...
@@ -4470,6 +4546,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
if
(
NamePart_
.
Length
!=
0
)
{
output
.
WriteRawTag
(
10
);
...
...
@@ -4603,6 +4683,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
location_
.
WriteTo
(
output
,
_repeated_location_codec
);
}
...
...
@@ -4761,6 +4845,10 @@ namespace Google.Protobuf.DescriptorProtos {
return
hash
;
}
public
override
string
ToString
()
{
return
pb
::
JsonFormatter
.
Default
.
Format
(
this
);
}
public
void
WriteTo
(
pb
::
CodedOutputStream
output
)
{
path_
.
WriteTo
(
output
,
_repeated_path_codec
);
span_
.
WriteTo
(
output
,
_repeated_span_codec
);
...
...
src/google/protobuf/compiler/csharp/csharp_field_base.h
View file @
5b9288e4
...
...
@@ -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
:
...
...
src/google/protobuf/compiler/csharp/csharp_map_field.cc
View file @
5b9288e4
...
...
@@ -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
)
{
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
5b9288e4
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment