Stream Helper Methods in Java
The stream classes provide all of the low-level methods necessary for encoding and decoding Ice types. However, it would be tedious and error-prone to manually encode complex Ice types such as classes, structs, and dictionaries using these low-level functions. For this reason, the Slice compiler generates helper methods for streaming complex Ice types.
We will use the following Slice definitions to demonstrate the language mapping:
Slice
module M { sequence<...> Seq; dictionary<...> Dict; struct S { ... } enum E { ... } }
The Slice compiler generates the corresponding helper classes and methods shown below:
Java
package M; public class SeqHelper { public static T[] read(com.zeroc.Ice.InputStream in); public static void write(com.zeroc.Ice.OutputStream out, T[] v); public static java.util.Optional<T[]> read(com.zeroc.Ice.InputStream in, int tag); public static void write(com.zeroc.Ice.OutputStream out, int tag, java.util.Optional<T[]> v); public static void write(com.zeroc.Ice.OutputStream out, int tag, T[] v); ... } public class DictHelper { public static java.util.Map<..., ...> read(com.zeroc.Ice.InputStream in); public static void write(com.zeroc.Ice.OutputStream out, java.util.Map<..., ...> v); public static java.util.Optional<java.util.Map<..., ...>> read(com.zeroc.Ice.InputStream in, int tag); public static void write(com.zeroc.Ice.OutputStream out, int tag, java.util.Optional<java.util.Map<..., ...>> v); public static void write(com.zeroc.Ice.OutputStream out, int tag, java.util.Map<..., ...> v); ... } public class S ... { public static S ice_read(com.zeroc.Ice.InputStream in); public static void ice_write(com.zeroc.Ice.OutputStream out, S v); public static java.util.Optional<S> ice_read(com.zeroc.Ice.InputStream in, int tag); public static void ice_write(com.zeroc.Ice.OutputStream out, int tag, java.util.Optional<S> v); public static void ice_write(com.zeroc.Ice.OutputStream out, int tag, S v); // Instance methods public void ice_readMembers(com.zeroc.Ice.InputStream in); public void ice_writeMembers(com.zeroc.Ice.OutputStream out); ... } public enum E ... { public static E ice_read(com.zeroc.Ice.InputStream in); public static void ice_write(com.zeroc.Ice.OutputStream out, E v); public static java.util.Optional<E> ice_read(com.zeroc.Ice.InputStream in, int tag); public static void ice_write(com.zeroc.Ice.OutputStream out, int tag, java.util.Optional<E> v); public static void ice_write(com.zeroc.Ice.OutputStream out, int tag, E v); // Instance method public void ice_write(com.zeroc.Ice.OutputStream out); ... }