| Index: third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
|
| diff --git a/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java b/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
|
| index 85cc97cbf6ebf047960f5494d4bbd5f116aac2ee..16ae80198dbc8b17459e41a8ae92e9326b575a0a 100644
|
| --- a/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
|
| +++ b/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
|
| @@ -10,10 +10,79 @@ import org.chromium.mojo.system.Core;
|
| * Base class for all mojo structs.
|
| */
|
| public abstract class Struct {
|
| +
|
| /**
|
| - * The base size of the encoded struct.
|
| + * The header for a mojo complex element.
|
| */
|
| - private final int mEncodedBaseSize;
|
| + public static final class DataHeader {
|
| + /**
|
| + * The size of a serialized header, in bytes.
|
| + */
|
| + public static final int HEADER_SIZE = 8;
|
| +
|
| + /**
|
| + * The offset of the size field.
|
| + */
|
| + public static final int SIZE_OFFSET = 0;
|
| +
|
| + /**
|
| + * The offset of the number of fields field.
|
| + */
|
| + public static final int ELEMENTS_OR_VERSION_OFFSET = 4;
|
| +
|
| + /**
|
| + * The size of the object owning this header.
|
| + */
|
| + public final int size;
|
| +
|
| + /**
|
| + * Number of element (for an array) or version (for a struct) of the object owning this
|
| + * header.
|
| + */
|
| + public final int elementsOrVersion;
|
| +
|
| + /**
|
| + * Constructor.
|
| + */
|
| + public DataHeader(int size, int elementsOrVersion) {
|
| + super();
|
| + this.size = size;
|
| + this.elementsOrVersion = elementsOrVersion;
|
| + }
|
| +
|
| + /**
|
| + * @see Object#hashCode()
|
| + */
|
| + @Override
|
| + public int hashCode() {
|
| + final int prime = 31;
|
| + int result = 1;
|
| + result = prime * result + elementsOrVersion;
|
| + result = prime * result + size;
|
| + return result;
|
| + }
|
| +
|
| + /**
|
| + * @see Object#equals(Object)
|
| + */
|
| + @Override
|
| + public boolean equals(Object object) {
|
| + if (object == this)
|
| + return true;
|
| + if (object == null)
|
| + return false;
|
| + if (getClass() != object.getClass())
|
| + return false;
|
| +
|
| + DataHeader other = (DataHeader) object;
|
| + return (elementsOrVersion == other.elementsOrVersion && size == other.size);
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * The base size of the struct.
|
| + */
|
| + protected final int mEncodedBaseSize;
|
|
|
| /**
|
| * The version of the struct.
|
| @@ -39,8 +108,8 @@ public abstract class Struct {
|
| /**
|
| * Returns the serialization of the struct. This method can close Handles.
|
| *
|
| - * @param core the |Core| implementation used to generate handles. Only used if the data
|
| - * structure being encoded contains interfaces, can be |null| otherwise.
|
| + * @param core the |Core| implementation used to generate handles. Only used if the |Struct|
|
| + * being encoded contains interfaces, can be |null| otherwise.
|
| */
|
| public Message serialize(Core core) {
|
| Encoder encoder = new Encoder(core, mEncodedBaseSize);
|
| @@ -63,7 +132,7 @@ public abstract class Struct {
|
| }
|
|
|
| /**
|
| - * Use the given encoder to serialize this data structure.
|
| + * Use the given encoder to serialize this struct.
|
| */
|
| protected abstract void encode(Encoder encoder);
|
| }
|
|
|