Index: mojo/bindings/java/src/org/chromium/mojo/bindings/Decoder.java |
diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/Decoder.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/Decoder.java |
index 86a038fc503fab3261a4f038c043686ef3fbeebb..55bca8e77a13d7a4b87ce24d5669da7ce074b33e 100644 |
--- a/mojo/bindings/java/src/org/chromium/mojo/bindings/Decoder.java |
+++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/Decoder.java |
@@ -40,10 +40,16 @@ public class Decoder { |
private final long mMaxMemory; |
/** |
+ * The number of handle in the message. |
+ */ |
+ private final long mNumberOfHandles; |
+ |
+ /** |
* Constructor. |
*/ |
- Validator(long maxMemory) { |
+ Validator(long maxMemory, int numberOfHandles) { |
mMaxMemory = maxMemory; |
+ mNumberOfHandles = numberOfHandles; |
} |
public void claimHandle(int handle) { |
@@ -51,6 +57,9 @@ public class Decoder { |
throw new DeserializationException( |
"Trying to access handle out of order."); |
} |
+ if (handle >= mNumberOfHandles) { |
+ throw new DeserializationException("Trying to access non present handle."); |
+ } |
mMinNextClaimedHandle = handle + 1; |
} |
@@ -92,7 +101,7 @@ public class Decoder { |
* @param message The message to decode. |
*/ |
public Decoder(Message message) { |
- this(message, new Validator(message.buffer.limit()), 0); |
+ this(message, new Validator(message.buffer.limit(), message.handles.size()), 0); |
} |
private Decoder(Message message, Validator validator, int baseOffset) { |
@@ -338,17 +347,29 @@ public class Decoder { |
/** |
* Deserializes a |ServiceHandle| at the given offset. |
*/ |
- public <S extends Interface> S readServiceInterface(int offset, Object builder) { |
- // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented. |
- throw new UnsupportedOperationException("Unimplemented operation"); |
+ public <S extends Interface> S readServiceInterface(int offset, |
+ Interface.Builder<S, ?> builder) { |
+ int index = readInt(offset); |
+ if (index == -1) { |
+ return null; |
+ } |
+ mValidator.claimHandle(index); |
+ MessagePipeHandle handle = mMessage.handles.get(index).toUntypedHandle() |
+ .toMessagePipeHandle(); |
+ @SuppressWarnings("unchecked") |
+ S service = (S) builder.connect(handle); |
+ return service; |
} |
/** |
* Deserializes a |InterfaceRequest| at the given offset. |
*/ |
public <S extends Interface> InterfaceRequest<S> readInterfaceRequest(int offset) { |
- // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented. |
- throw new UnsupportedOperationException("Unimplemented operation"); |
+ MessagePipeHandle handle = readMessagePipeHandle(offset); |
+ if (handle == null) { |
+ return null; |
+ } |
+ return new InterfaceRequest<S>(handle); |
} |
/** |
@@ -453,9 +474,18 @@ public class Decoder { |
/** |
* Deserializes an array of |ServiceHandle| at the given offset. |
*/ |
- public <S extends Interface> S[] readServiceInterfaces(int offset, Object builder) { |
- // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented. |
- throw new UnsupportedOperationException("Unimplemented operation"); |
+ public <S extends Interface> S[] readServiceInterfaces(int offset, |
+ Interface.Builder<S, ?> builder) { |
+ Decoder d = readPointer(offset); |
+ if (d == null) { |
+ return null; |
+ } |
+ DataHeader si = d.readDataHeader(); |
+ S[] result = builder.newArray(si.numFields); |
+ for (int i = 0; i < result.length; ++i) { |
+ result[i] = d.readServiceInterface(8 + 4 * i, builder); |
+ } |
+ return result; |
} |
/** |