| Index: mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
|
| diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
|
| index f826a8e034c9215a8a8e6496e05c716619a32d0d..14bdbf1e7cbc1eb376ea6c39590804f41a4293d9 100644
|
| --- a/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
|
| +++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/Message.java
|
| @@ -10,6 +10,7 @@ import org.chromium.mojo.system.MessagePipeHandle.ReadMessageResult;
|
| import org.chromium.mojo.system.MojoResult;
|
|
|
| import java.nio.ByteBuffer;
|
| +import java.nio.ByteOrder;
|
| import java.util.List;
|
|
|
| import javax.annotation.Nullable;
|
| @@ -29,6 +30,9 @@ public final class Message {
|
| */
|
| public final List<? extends Handle> handles;
|
|
|
| + private MessageHeader mHeader = null;
|
| + private Message mPayload = null;
|
| +
|
| /**
|
| * Constructor.
|
| *
|
| @@ -60,4 +64,39 @@ public final class Message {
|
| }
|
| return result.getMojoResult();
|
| }
|
| +
|
| + /**
|
| + * Returns the header of the given message. This should only be called on message that are known
|
| + * to have a header. This will throw a {@link DeserializationException} it the start of the
|
| + * message is not a valid header.
|
| + */
|
| + public MessageHeader getHeader() {
|
| + if (mHeader == null) {
|
| + mHeader = new org.chromium.mojo.bindings.MessageHeader(this);
|
| + }
|
| + return mHeader;
|
| + }
|
| +
|
| + /**
|
| + * Returns the payload of the message. This should only be called on message that are known to
|
| + * have a header.
|
| + */
|
| + public Message getPayload() {
|
| + if (mPayload == null) {
|
| + ByteBuffer truncatedBuffer = ((ByteBuffer) buffer.position(
|
| + getHeader().getSize())).slice();
|
| + truncatedBuffer.order(ByteOrder.nativeOrder());
|
| + mPayload = new Message(truncatedBuffer, handles);
|
| + }
|
| + return mPayload;
|
| + }
|
| +
|
| + /**
|
| + * Reset the cache header. Used by {@link MessageHeader} when it modified the message buffer.
|
| + */
|
| + void resetHeader() {
|
| + mHeader = null;
|
| + mPayload = null;
|
| + }
|
| +
|
| }
|
|
|