Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java

Issue 2327103004: Mojo Java Bindings: expose public API for struct serialization. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
index 85cc97cbf6ebf047960f5494d4bbd5f116aac2ee..14f4e1e7261cd32657b023af5bbee52dfadff690 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java
@@ -6,6 +6,8 @@ package org.chromium.mojo.bindings;
import org.chromium.mojo.system.Core;
+import java.nio.ByteBuffer;
+
/**
* Base class for all mojo structs.
*/
@@ -49,6 +51,23 @@ public abstract class Struct {
}
/**
+ * Similar to the method above, but returns the serialization result as |ByteBuffer|.
+ *
+ * @throws UnsupportedOperationException if the struct contains interfaces or handles.
+ * @throws SerializationException on serialization failure.
+ */
+ public ByteBuffer serialize() {
+ // If the struct contains interfaces which require a non-null |Core| instance, it will throw
+ // UnsupportedOperationException.
+ Message message = serialize(null);
+
+ if (!message.getHandles().isEmpty())
+ throw new UnsupportedOperationException("Handles are discarded.");
+
+ return message.getData();
+ }
+
+ /**
* Returns the serialization of the struct prepended with the given header.
*
* @param header the header to prepend to the returned message.

Powered by Google App Engine
This is Rietveld 408576698