| Index: mojo/bindings/java/src/org/chromium/mojo/bindings/Encoder.java
|
| diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/Encoder.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/Encoder.java
|
| index 9ec2cb248e0bb8cc5e697a29cdec93f84398bbf8..70b15ee332410f9784c35c59f7a4ffe371bc2fdc 100644
|
| --- a/mojo/bindings/java/src/org/chromium/mojo/bindings/Encoder.java
|
| +++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/Encoder.java
|
| @@ -7,6 +7,8 @@ package org.chromium.mojo.bindings;
|
| import org.chromium.mojo.bindings.Struct.DataHeader;
|
| import org.chromium.mojo.system.Core;
|
| import org.chromium.mojo.system.Handle;
|
| +import org.chromium.mojo.system.MessagePipeHandle;
|
| +import org.chromium.mojo.system.Pair;
|
|
|
| import java.nio.ByteBuffer;
|
| import java.nio.ByteOrder;
|
| @@ -139,7 +141,6 @@ public class Encoder {
|
| Encoder result = new Encoder(mEncoderState);
|
| result.encode(dataHeader);
|
| return result;
|
| -
|
| }
|
|
|
| /**
|
| @@ -243,25 +244,41 @@ public class Encoder {
|
| /**
|
| * Encode an {@link Interface}.
|
| */
|
| - public <T extends Interface> void encode(T v, int offset, Object builder) {
|
| + public <T extends Interface> void encode(T v, int offset,
|
| + Interface.Builder<T, ?> builder) {
|
| + if (v == null) {
|
| + encode(-1, offset);
|
| + return;
|
| + }
|
| if (mEncoderState.core == null) {
|
| throw new UnsupportedOperationException(
|
| "The encoder has been created without a Core. It can't encode an interface.");
|
| }
|
| - // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented.
|
| - throw new UnsupportedOperationException("Unimplemented operation");
|
| + if (v instanceof Interface.Proxy) {
|
| + Interface.Proxy proxy = (Interface.Proxy) v;
|
| + if (proxy.getMessageReceiver() instanceof HandleOwner) {
|
| + encode(((HandleOwner<?>) proxy.getMessageReceiver()).passHandle(), offset);
|
| + return;
|
| + }
|
| + }
|
| + Pair<MessagePipeHandle, MessagePipeHandle> handles = mEncoderState.core.createMessagePipe();
|
| + builder.bind(handles.first, v);
|
| + encode(handles.second, offset);
|
| }
|
|
|
| /**
|
| * Encode an {@link InterfaceRequest}.
|
| */
|
| public <T extends Interface> void encode(InterfaceRequest<T> v, int offset) {
|
| + if (v == null) {
|
| + encode(-1, offset);
|
| + return;
|
| + }
|
| if (mEncoderState.core == null) {
|
| throw new UnsupportedOperationException(
|
| "The encoder has been created without a Core. It can't encode an interface.");
|
| }
|
| - // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented.
|
| - throw new UnsupportedOperationException("Unimplemented operation");
|
| + encode(v.passHandle(), offset);
|
| }
|
|
|
| /**
|
| @@ -347,7 +364,7 @@ public class Encoder {
|
| }
|
|
|
| /**
|
| - * Encodes an array of doubles.
|
| + * Encodes an array of doubles.result
|
| */
|
| public void encode(double[] v, int offset) {
|
| if (v == null) {
|
| @@ -374,7 +391,8 @@ public class Encoder {
|
| /**
|
| * Encodes an array of {@link Interface}.
|
| */
|
| - public <T extends Interface> void encode(T[] v, int offset, Object builder) {
|
| + public <T extends Interface> void encode(T[] v, int offset,
|
| + Interface.Builder<T, ?> builder) {
|
| if (v == null) {
|
| encodeNullPointer(offset);
|
| return;
|
|
|