Chromium Code Reviews| Index: mojo/bindings/java/src/org/chromium/mojo/bindings/Struct.java |
| diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/Struct.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/Struct.java |
| index f7c16a2decb0fa75c54e0684ed020a1b6bfa9163..b131e3f04e23e1ffa2758d938e9146bc5485b8aa 100644 |
| --- a/mojo/bindings/java/src/org/chromium/mojo/bindings/Struct.java |
| +++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/Struct.java |
| @@ -42,6 +42,37 @@ public abstract class Struct { |
| this.size = size; |
| this.numFields = numFields; |
| } |
| + |
| + /** |
| + * @see Object#hashCode() |
| + */ |
| + @Override |
| + public int hashCode() { |
| + final int prime = 31; |
| + int result = 1; |
| + result = prime * result + numFields; |
| + result = prime * result + size; |
| + return result; |
| + } |
| + |
| + /** |
| + * @see Object#equals(Object) |
| + */ |
| + @Override |
| + public boolean equals(Object object) { |
| + if (this == object) |
| + return true; |
| + if (object == null) |
| + return false; |
| + if (getClass() != object.getClass()) |
| + return false; |
| + DataHeader other = (DataHeader) object; |
| + if (numFields != other.numFields) |
| + return false; |
| + if (size != other.size) |
| + return false; |
| + return true; |
|
rmcilroy
2014/07/16 15:06:44
ditto with MessageHeader equals() comment.
qsr
2014/07/16 15:58:38
Done, with the same comment about not removing new
|
| + } |
| } |
| /** |
| @@ -73,4 +104,18 @@ public abstract class Struct { |
| return encoder.getMessage(); |
| } |
| + /** |
| + * Returns the serialization of the struct prepended with the given header. |
| + * |
| + * @param header the header to prepend to the returned message. |
| + * @param core the |Core| implementation used to generate handles. Only used if the |Struct| |
| + * being encoded contains interfaces, can be |null| otherwise. |
| + */ |
| + public MessageWithHeader serializeWithHeader(Core core, MessageHeader header) { |
| + Encoder encoder = new Encoder(core, mEncodedBaseSize + header.getSize()); |
| + header.encode(encoder); |
| + encode(encoder); |
| + return new MessageWithHeader(encoder.getMessage(), header); |
| + } |
| + |
| } |