<Union TypeSpec> ::= Cop:Proto::Union:n <MP TypeSpec>n | Cop:Proto::RecUnion:n <MP TypeSpec>nA Cop:Proto::Union:n or Cop:Proto::RecUnion:n operator node packet is used to specify a union of n prototype trees (<MP TypeSpec>'s). Again, the only difference between these operators is that a Cop:Proto::RecUnion:n operator designates a union as a target for a recursive type specification (see section 3.2.3 for details). As for Struct and RecStruct, the index n indicates that each of the n arguments following the operator is again a prototype tree (MP TypeSpec). At data communication time, a union discriminator is first transmitted as an IMP_Uint32 followed by a prototyped data tree. The valid range for the union discrimination index is . An index i between 1 and n specifies that the corresponding prototyped data tree is as specified by the ith argument of the Cop:Proto::Union:n operator node packet.
The example in figure 4 illustrates the use of the Cop:Proto::Union:n.
union { MP_Uint32 uint; MP_Sint32 sint; MP_ApInt apint; } array[3];
The union operator on line 1 indicates that there are three prototypes (fields) in the union. These are given on lines 2 - 4. The prototyped data tree begin on line 5 with an IMP_Uint32 serving as union discriminator. The value is 1, indicating that the prototype with index 1 (defined on line 3) specifies the type of the following data limb. Once a receiver has consumed the data according to the prototype, it is positioned to read the next discriminator on line 6. This would proceed until all 3 arguments had been read.