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
553d39f9
Commit
553d39f9
authored
Sep 02, 2014
by
Brian Duff
Committed by
Gerrit Code Review
Sep 02, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Add MessageNano.messageNanoEquals()."
parents
9d9cb7c3
72881dad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
MessageNano.java
java/src/main/java/com/google/protobuf/nano/MessageNano.java
+26
-0
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+3
-0
No files found.
java/src/main/java/com/google/protobuf/nano/MessageNano.java
View file @
553d39f9
...
...
@@ -31,6 +31,7 @@
package
com
.
google
.
protobuf
.
nano
;
import
java.io.IOException
;
import
java.util.Arrays
;
/**
* Abstract interface implemented by Protocol Message objects.
...
...
@@ -150,6 +151,31 @@ public abstract class MessageNano {
}
}
/**
* Compares two {@code MessageNano}s and returns true if the message's are the same class and
* have serialized form equality (i.e. all of the field values are the same).
*/
public
static
final
boolean
messageNanoEquals
(
MessageNano
a
,
MessageNano
b
)
{
if
(
a
==
b
)
{
return
true
;
}
if
(
a
==
null
||
b
==
null
)
{
return
false
;
}
if
(
a
.
getClass
()
!=
b
.
getClass
())
{
return
false
;
}
final
int
serializedSize
=
a
.
getSerializedSize
();
if
(
b
.
getSerializedSize
()
!=
serializedSize
)
{
return
false
;
}
final
byte
[]
aByteArray
=
new
byte
[
serializedSize
];
final
byte
[]
bByteArray
=
new
byte
[
serializedSize
];
toByteArray
(
a
,
aByteArray
,
0
,
serializedSize
);
toByteArray
(
b
,
bByteArray
,
0
,
serializedSize
);
return
Arrays
.
equals
(
aByteArray
,
bByteArray
);
}
/**
* Returns a string that is (mostly) compatible with ProtoBuffer's TextFormat. Note that groups
* (which are deprecated) are not serialized with the correct field name.
...
...
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
553d39f9
...
...
@@ -3212,6 +3212,9 @@ public class NanoTest extends TestCase {
TestAllTypesNano
a
=
createMessageForHashCodeEqualsTest
();
TestAllTypesNano
aEquivalent
=
createMessageForHashCodeEqualsTest
();
assertTrue
(
MessageNano
.
messageNanoEquals
(
a
,
aEquivalent
));
assertFalse
(
MessageNano
.
messageNanoEquals
(
a
,
new
TestAllTypesNano
()));
// Null and empty array for repeated fields equality:
TestAllTypesNano
b
=
createMessageForHashCodeEqualsTest
();
b
.
repeatedBool
=
null
;
...
...
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