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
801b169b
Commit
801b169b
authored
Aug 03, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addressed issues raised in code review. Will merge when green.
parent
16e272e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
26 deletions
+18
-26
unittest_issues.proto
csharp/protos/extest/unittest_issues.proto
+4
-1
JsonFormatter.cs
csharp/src/Google.Protobuf/JsonFormatter.cs
+14
-25
No files found.
csharp/protos/extest/unittest_issues.proto
View file @
801b169b
...
...
@@ -97,7 +97,10 @@ message TestJsonFieldOrdering {
// ordering.
// TestFieldOrderings in unittest_proto3.proto is similar,
// but doesn't include oneofs.
// TODO: Consider adding
// TODO: Consider adding oneofs to TestFieldOrderings, although
// that will require fixing other tests in multiple platforms.
// Alternatively, consider just adding this to
// unittest_proto3.proto if multiple platforms want it.
int32
plain_int32
=
4
;
...
...
csharp/src/Google.Protobuf/JsonFormatter.cs
View file @
801b169b
...
...
@@ -433,32 +433,13 @@ namespace Google.Protobuf
// Use .NET's formatting for the value down to the second, including an opening double quote (as it's a string value)
DateTime
dateTime
=
normalized
.
ToDateTime
();
builder
.
Append
(
dateTime
.
ToString
(
"yyyy'-'MM'-'dd'T'HH:mm:ss"
,
CultureInfo
.
InvariantCulture
));
if
(
normalized
.
Nanos
!=
0
)
{
builder
.
Append
(
'.'
);
// Output to 3, 6 or 9 digits.
if
(
normalized
.
Nanos
%
1000000
==
0
)
{
builder
.
Append
((
normalized
.
Nanos
/
1000000
).
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
}
else
if
(
normalized
.
Nanos
%
1000
==
0
)
{
builder
.
Append
((
normalized
.
Nanos
/
1000
).
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
}
else
{
builder
.
Append
((
normalized
.
Nanos
).
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
}
}
AppendNanoseconds
(
builder
,
Math
.
Abs
(
normalized
.
Nanos
));
builder
.
Append
(
'Z'
);
}
private
void
WriteDuration
(
StringBuilder
builder
,
IMessage
value
)
{
// TODO: In the common case where this *is* using the built-in Timestamp type, we could
// avoid all the reflection at this point, by casting to Timestamp. In the interests of
// avoiding subtle bugs, don't do that until we've implemented DynamicMessage so that we can prove
// it still works in that case.
// TODO: Same as for WriteTimestamp
int
nanos
=
(
int
)
value
.
Descriptor
.
Fields
[
Duration
.
NanosFieldNumber
].
Accessor
.
GetValue
(
value
);
long
seconds
=
(
long
)
value
.
Descriptor
.
Fields
[
Duration
.
SecondsFieldNumber
].
Accessor
.
GetValue
(
value
);
...
...
@@ -473,7 +454,16 @@ namespace Google.Protobuf
}
builder
.
Append
(
normalized
.
Seconds
.
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
nanos
=
Math
.
Abs
(
normalized
.
Nanos
);
AppendNanoseconds
(
builder
,
Math
.
Abs
(
normalized
.
Nanos
));
builder
.
Append
(
's'
);
}
/// <summary>
/// Appends a number of nanoseconds to a StringBuilder. Either 0 digits are added (in which
/// case no "." is appended), or 3 6 or 9 digits.
/// </summary>
private
static
void
AppendNanoseconds
(
StringBuilder
builder
,
int
nanos
)
{
if
(
nanos
!=
0
)
{
builder
.
Append
(
'.'
);
...
...
@@ -482,7 +472,7 @@ namespace Google.Protobuf
{
builder
.
Append
((
nanos
/
1000000
).
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
}
else
if
(
n
ormalized
.
N
anos
%
1000
==
0
)
else
if
(
nanos
%
1000
==
0
)
{
builder
.
Append
((
nanos
/
1000
).
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
}
...
...
@@ -491,7 +481,6 @@ namespace Google.Protobuf
builder
.
Append
(
nanos
.
ToString
(
"d"
,
CultureInfo
.
InvariantCulture
));
}
}
builder
.
Append
(
's'
);
}
private
void
WriteList
(
StringBuilder
builder
,
IFieldAccessor
accessor
,
IList
list
)
...
...
@@ -647,7 +636,7 @@ namespace Google.Protobuf
}
}
builder
.
Append
(
'"'
);
}
}
private
const
string
Hex
=
"0123456789abcdef"
;
private
static
void
HexEncodeUtf16CodeUnit
(
StringBuilder
builder
,
char
c
)
...
...
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