Table of contents
As described earlier, template fields have a presence attribute. If set to "optional", the field is optional in the output message. To omit the field in the output message, a special NULL value is put into the encoded message.
A field is nullable in certain cases and affects the normal decoding of encoded fields. For example, optional integer fields are offset by 1 if positive to make room for the reserved value 0 (used to indicate NULL). This is not the case for mandatory integer fields.
The following Table 3.2 shows the rules of determining field nullability.
Table 3.2 Field Nullability Matrix
In your code, you will want each template field object to implement a method for determining field nullability.
public boolean isFieldNullable();
In our FAST library, we have two decoders which perform field value extracts from the stream:
- NullableDataTypeDecoder for nullable fields (can return null as field value).
- NonNullableDataTypeDecoder for non-nullable fields (cannot return null as field value).
Before assigning a decoder for the template field object, we check field nullability to choose the right one:
dataTypeDecoder = isFieldNullable() ? NullableDataTypeDecoder.getDefaultInstance() : NonNullableDataTypeDecoder.getDefaultInstance();