Inspirel banner

Programming Distributed Systems with YAMI4

3.11.4 .NET

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 .NET 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. In this regard the .NET implementation is very similar to the Java one.

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, int.MAX_VALUE can be used:

List<byte[]> buffers = params.Serialize(int.MAX_VALUE);

If the preferred size is other than int.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);