<< back to guide home

Dana can automatically convert Data instances to byte arrays, as long as the Data type includes only fields of primitive type (including fixed-size arrays of primitive type).

This is done by using the notation dana.serial(x). This operation returns a reference to a byte array containing the contents of x as a stream of bytes. This reference is fully writable, allowing the individual bytes of a data item to be modified.

An example use of this would be:

data Person {
    char name[50]
    int age

Person p = new Person()
byte stream[] = dana.serial(p)
dana.serial(p) =[] stream