Each CompoundObject consists of a type and an array of children which are references to other objects.
When serialized, a CompoundObject is formatted as follows:
SerializedCompoundObject {
Integer objectType;
Integer childArrayLength;
SerializedCompoundObject children[0..childArrayLength-1];
}
The objectType field is an Integer which indexes into the serializer's array of object types. This array initially contains a set of predefined types, and is augmented by any NEW_TYPE primitives encoded in the stream.
The number of children of this object is encoded as an Integer immediately after the objectType field. This allows a parser to preallocate the array of children.
The children of this object are encoded successively after the childArrayLength field. Any of these could be either a PrimitiveObject or another CompoundObject. By including BACK_REFERENCE primitives, an object can refer to another object in the graph, or create a circular reference.
The primitive object representing the Integer zero would be encoded as:
02 00A CompoundObject with objectType==32, two null children, and three of the above zero integer children would be encoded as:
20 // objectType = 32 05 // childArrayLength = 5 00 // child 0, objectType=NULL 00 // child 1, objectType=NULL 02 00 // child 2, objectType=INTEGER, value=0 02 00 // child 3, objectType=INTEGER, value=0 02 00 // child 4, objectType=INTEGER, value=0