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
b8f5dad1
Commit
b8f5dad1
authored
Jul 09, 2013
by
Ulas Kirazci
Committed by
Gerrit Code Review
Jul 09, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Make it possible to use MessageNano.mergeFrom without casting."
parents
499f47ff
a9c4e082
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
MessageNano.java
java/src/main/java/com/google/protobuf/nano/MessageNano.java
+3
-3
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+9
-0
javanano_message.cc
src/google/protobuf/compiler/javanano/javanano_message.cc
+1
-1
No files found.
java/src/main/java/com/google/protobuf/nano/MessageNano.java
View file @
b8f5dad1
...
...
@@ -101,7 +101,7 @@ public abstract class MessageNano {
* Parse {@code data} as a message of this type and merge it with the
* message being built.
*/
public
static
final
MessageNano
mergeFrom
(
MessageNano
msg
,
final
byte
[]
data
)
public
static
final
<
T
extends
MessageNano
>
T
mergeFrom
(
T
msg
,
final
byte
[]
data
)
throws
InvalidProtocolBufferNanoException
{
return
mergeFrom
(
msg
,
data
,
0
,
data
.
length
);
}
...
...
@@ -110,8 +110,8 @@ public abstract class MessageNano {
* Parse {@code data} as a message of this type and merge it with the
* message being built.
*/
public
static
final
MessageNano
mergeFrom
(
MessageNano
msg
,
final
byte
[]
data
,
final
int
off
,
final
int
len
)
throws
InvalidProtocolBufferNanoException
{
public
static
final
<
T
extends
MessageNano
>
T
mergeFrom
(
T
msg
,
final
byte
[]
data
,
final
int
off
,
final
int
len
)
throws
InvalidProtocolBufferNanoException
{
try
{
final
CodedInputByteBufferNano
input
=
CodedInputByteBufferNano
.
newInstance
(
data
,
off
,
len
);
...
...
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
b8f5dad1
...
...
@@ -2241,6 +2241,15 @@ public class NanoTest extends TestCase {
assertEquals
(
0
,
MessageNano
.
toByteArray
(
deserialized
).
length
);
}
public
void
testMergeFrom
()
throws
Exception
{
SimpleMessageNano
message
=
new
SimpleMessageNano
();
message
.
d
=
123
;
byte
[]
bytes
=
MessageNano
.
toByteArray
(
message
);
SimpleMessageNano
newMessage
=
MessageNano
.
mergeFrom
(
new
SimpleMessageNano
(),
bytes
);
assertEquals
(
message
.
d
,
newMessage
.
d
);
}
private
<
T
>
List
<
T
>
list
(
T
first
,
T
...
remaining
)
{
List
<
T
>
list
=
new
ArrayList
<
T
>();
list
.
add
(
first
);
...
...
src/google/protobuf/compiler/javanano/javanano_message.cc
View file @
b8f5dad1
...
...
@@ -362,7 +362,7 @@ GenerateParseFromMethods(io::Printer* printer) {
printer
->
Print
(
"public $static$ $classname$ parseFrom(byte[] data)
\n
"
" throws com.google.protobuf.nano.InvalidProtocolBufferNanoException {
\n
"
" return
($classname$)
com.google.protobuf.nano.MessageNano.mergeFrom(new $classname$(), data);
\n
"
" return com.google.protobuf.nano.MessageNano.mergeFrom(new $classname$(), data);
\n
"
"}
\n
"
"
\n
"
"public $static$ $classname$ parseFrom(
\n
"
...
...
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