Errata exists for this version of the document.
Structures with optional fields shall be encoded as JSON objects as shown in Table 33.
Table 33 – JSON Object Definition for a Structures with Optional Fields
Name |
Description |
EncodingMask |
A bit mask indicating what fields are encoded in the structure (see 5.2.7) This mask is encoded as a JSON number. The bits are sequentially assigned to optional fields in the order that they are defined. |
<FieldName> |
The fields structure encoded according to the rules defined for their DataType. |
For the non-reversible form, Structures with optional fields are encoded like Structures.
If a Structure with optional fields is subtyped, the subtypes extend the EncodingMask (e) defined for the the parent.
The following is an example of a structure with optional fields using C++ syntax:
struct TypeA
{
Int32 X;
Int32* O1;
SByte Y;
Int32* O2;
};
O1 and O2 are optional fields where a NULL indicates that the field is not present.
Assume that O1 is not specified and the value of O2 is 0.
The reversible encoding would be:
{ "EncodingMask": 2 "X": 1, "Y": 2 }
Where decoders would assign the default value of 0 to O2 since the mask bit is set, however, the field was omitted (this is the behaviour defined for the Int32 DataType). Decoders would mark O1 as ‘not specified’.