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
dc8149fc
Commit
dc8149fc
authored
Aug 13, 2013
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize FromBase64String to return Empty when presented with an empty string.
This fixes issue 61.
parent
f86edcbb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
ByteStringTest.cs
src/ProtocolBuffers.Test/ByteStringTest.cs
+18
-0
ByteString.cs
src/ProtocolBuffers/ByteString.cs
+3
-1
No files found.
src/ProtocolBuffers.Test/ByteStringTest.cs
View file @
dc8149fc
...
...
@@ -34,6 +34,7 @@
#endregion
using
System
;
using
System.Text
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
...
...
@@ -127,5 +128,21 @@ namespace Google.ProtocolBuffers
ByteString
bs
=
ByteString
.
CopyFrom
(
"\u20ac"
,
Encoding
.
Unicode
);
Assert
.
AreEqual
(
"\u20ac"
,
bs
.
ToString
(
Encoding
.
Unicode
));
}
[
TestMethod
]
public
void
FromBase64_WithText
()
{
byte
[]
data
=
new
byte
[]
{
0
,
1
,
2
,
3
,
4
,
5
,
6
};
string
base64
=
Convert
.
ToBase64String
(
data
);
ByteString
bs
=
ByteString
.
FromBase64
(
base64
);
TestUtil
.
AssertBytesEqual
(
data
,
bs
.
ToByteArray
());
}
[
TestMethod
]
public
void
FromBase64_Empty
()
{
// Optimization which also fixes issue 61.
Assert
.
AreSame
(
ByteString
.
Empty
,
ByteString
.
FromBase64
(
""
));
}
}
}
\ No newline at end of file
src/ProtocolBuffers/ByteString.cs
View file @
dc8149fc
...
...
@@ -129,7 +129,9 @@ namespace Google.ProtocolBuffers
/// </summary>
public
static
ByteString
FromBase64
(
string
bytes
)
{
return
new
ByteString
(
Convert
.
FromBase64String
(
bytes
));
// By handling the empty string explicitly, we not only optimize but we fix a
// problem on CF 2.0. See issue 61 for details.
return
bytes
==
""
?
Empty
:
new
ByteString
(
Convert
.
FromBase64String
(
bytes
));
}
/// <summary>
...
...
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