Inspirel banner

Programming Distributed Systems with YAMI4

3.5.4 .NET

Simple values (boolean, integer, long and double) can be set with a single operation:

params.SetInteger("age", 25);

Above, a new entry named ``age'' is created (or replaces the existing one with the same name) and an integer value 25 is set as its content.

String values are also handled directly:

params.SetString("first_name", "John");

The binary values are handled with byte[] array type to describe the data buffer:

byte[] songBuffer = GetSongFromSomewhere();

params.SetBinary("favorite_song", songBuffer);

In both string and binary cases, the arrays are not copied into the internal storage of the parameters object - in the case of string it is not a problem, since strings are immutable, but binary buffers are shared and care should be taken to ensure that the buffer contains the intended value at the time when it is used for serialization.

Arrays are handled similarly to binary buffers - that is, array objects of relevant type are used as buffers:

int[] myNumbers = ...;

params.SetIntegerArray("favorite_numbers", myNumbers);

Arrays of strings are also handled this way:

string[] friends = {"Alice", "Bob", "Nicole"};

params.SetStringArray("friends", friends);

Arrays of binary values are passed as byte[][] buffers.

Nested parameters allow to build some form of hierarchic data structures. Nested parameters objects are just inserted into existing objects as any other type:

Parameters nested = new Parameters();
// ...
params.SetNestedParameters("address", nested);

The nested object declared above is a stand-alone object, but after setting it in another object its state is shared (aliased) as with array objects of any type.

The nested object declared above can be used just as any regular parameters object, for example:

nested.SetString("street", "Flowery");
nested.SetInteger("house_number", 17);

Similar rules apply for nested parameters arrays.

All the example statements in this section filled a single parameters object with six entries (``age'', ``first_name'', ``favorite_song'', ``favorite_numbers'' ``friends'' and ``address''), one them being an array with 3 elements and one being a nested parameters with 2 entries.