The specification of basic types is done using CommonMetaType (Cmt) node packets whose value
MP_ProtoDict
)
More precisely, a basic type specification is defined by:2
For a first simple example we encode an array of 1000
MP_Real32_t
numbers.
The resulting MP Tree is shown in a stylized fashion in figure
1.
The actual encoding is binary and not easily human readable.
A fragment of the code to produce the tree is shown in figure
2.
Line (1) contains the common operator Array
defined in the
Proto dictionary.
It has a single annotation and 1000 arguments.
The annotation is a prototype annotation and is given on lines (2 -
3).
It specifies that each element of the array is of
the type IMP_Real32.
Recall that the common meta type packet (Cmt) specifies the type of
data that will appear in this position of the MP Tree that follows.
The prototyped data tree follows, beginning on line (4).
Note that there are no node packet headers to individually
specify the type of each element of the prototyped data tree (this is
the job of the prototype).
Recall that the IMP_<type>s represent data only - there is no
attached type information.
An unprototyped version of figure 1 requires 8,008 bytes:
8 bytes for the Array node packet and 8,000 bytes for the array
elements, 4,000 bytes of which is the actual data (1,000 32-bit floats)
and the remaining 4,000 bytes are the overhead for the node packet
headers.
Using the prototype mechanism to specify the element type of the
array reduces the total size of the array's encoding from 8,008
bytes (4,008 bytes total overhead) to 4,016 bytes (16 bytes of
overhead).
An important point to make about prototypes is that the size
of the prototype is largely independent of the size of the data.
In the example above, the overhead for the prototype stays at 16 bytes
even if, for example, the size of the data doubles (4 to 8 bytes for an
IMP_Real64
) or the length of the array doubles.