Inspirel banner

Programming Distributed Systems with YAMI4

3.11.3 Java

In order to serialize a given parameters object, it is only necessary to provide the preferred size of the target buffer. The object will be serialized into a list of buffers and the number of buffers in the resulting list will depend on the total amount of data to be serialized and on the preferred buffer size. The last buffer in the list might be smaller than required if the requested size would be bigger than necessary to hold all the data.

Note:

Parameters implementation in Java differs from Ada and C++ in that it does not allow serialization into user-supplied buffers of arbitrary sizes - instead it is the parameters object that will allocate the buffers as the serialization processes.

If only one continuous buffer is required, the preferred size should be bigger than what is needed to hold all the data. Since there is no function to compute this value precisely, Integer.MAX_VALUE can be used:

List<byte[]> buffers = params.serialize(Integer.MAX_VALUE);

If the preferred size is other than Integer.MAX_VALUE then it must be a multiple of 4.

Deserialization is symmetric - if the buffers are already filled with data, the parameters object can be reconstructed with a single call:

params.deserialize(buffers);