Table of contents

 

The default value associated with this operator is added to the output message unless the value is included in the encoded message.
This diagram shows the decoding algorithm for fields defined with the Default Operator:

Decoding algorithm of fields with Default Operator

Picture 3.11 - "Decoding algorithm of fields with Default Operator"

An implementation of this algorithm:

public int decode(byte[] encodedData, int offset,
                  PresenceMap presenceMap, OutputMessage message) {
    Object decodedValue = null;
    if (presenceMap.isNextPMapBitSet()) {
        offset = dataTypeDecoder.decode(encodedData, offset, templateField);
        decodedValue = getFieldValue();
    } else {
        decodedValue = getInitialValue();
    } 
    if (decodedValue != null) {
        message.addValue(tagId, decodedValue);
    } else {
        if (isMandatory) {
            throw new RuntimeException(
                "Mandatory field decoded value can not be NULL");
    }
    return offset;
}
 
public void reset() {
    // Default fields never change their initial value
    //so there is no need to reset them
}
 
public boolean isPMapBitExist() {
    // Default fields require presence map bit
    return true;
}
 
public boolean isFieldNullable() {
    // If isMandatory false the Default field could has the null representation
    //of field value and does not apear in the output fix message
    return !isMandatory;
}