Define the format

The first step with Argot is defining the language. These are the
data structures that the device or application uses in the messages they send and
receive. Here's a few simple messages for a coloured light.
It defines a colour type with red, green and blue. Following this, the set_colour message shows a reference to
the colour data type.

It's important to note that the Argot language is designed around describing binary data.
For example, the encoding of the colour data type is three unsigned
single bytes (uint8) in a sequence. In addition, as the set_colour only references the colour type, it uses
exactly the same number of bits as the colour type. The colour object as a stream would be encoded as follows:

Define the types in your language

The next step is to define how the various types are represented in the host language.
Here's an example of the colour data type in Java.

@ArgotMarshaller(ArgotMarshaller.Marshaller.ANNOTATION)
public class Colour
{
public static final String TYPENAME = "colour";
@ArgotTag("red")
public short red;
@ArgotTag("green")
public short green;
@ArgotTag("blue")
public short blue;
}

Argot has different types of marshallers depending on the data being represented. You are also free to write your
own marshaller for specific types if required. This can be useful when dealing with complex data structures.

Load and bind the library

In Argot, all data types are stored in a type library. With the data types defined and the object created in Java,
the next step is to compile and load the type library.

Write information to stream

To write out the information to an output stream, a SetColour instance is created. A TypeOutputStream
is created which maps the object to the stream. The TypeMap provides the ability to perform type agreement and restrict
the specific types used on a specific data stream. This will be covered in depth in future examples.

The setColour instance is written as an object to the stream. Argot performs
the marshalling based on the Argot specification.
The result of writing the colour object to the stream is that three bytes are written to the byte array.

Read information from a stream

To read the setColour message from the data stream, a TypeInputStream is created. The object is marshalled from the stream when given the Argot type name.