Table of contents

 

If the field value is present in the encoded message (its PMap bit is set) the decoded value is used as the output value. Otherwise, the increment operator uses the previous value and adds one to it to yield the output value. That output value updates the previous value for next time.
This operator works with integers only.

The below diagram illustrates the Increment operator decoding algorithm:

Decoding algorithm of fields with Increment Operator

Picture 3.13 - "Decoding algorithm of fields with Increment Operator"

An implementation of this algorithm:

public int decode(byte[] encodedData, int offset, PresenceMap presenceMap, OutputMessage message) {
    if (presenceMap.isNextPMapBitSet()) {
        offset = dataTypeDecoder.decode(encodedData, offset, templateField);
        Object decodedValue = getFieldValue();
        if (decodedValue != null) {
            message.addValue(tagId, decodedValue);
            setPreviousValue(decodedValue);
            isUndefinedPrevValue = false;
        } else {
            if (isMandatory) {
                throw new RuntimeException("Mandatory field decoded value can not be NULL");
            } else {
                 setPreviousValue(null);
            }
        }
    } else {
        if (getPreviousValue() != null) {
            if (!isUndefinedPrevValue) {
                incrementPrevFieldValue();
            }             
            // add field into the message
            message.addValue(tagId, getPreviousValue());
        } else {
            if (isMandatory) {
                throw new RuntimeException("Mandatory field decoded value can not be NULL");
            }
        }
    }
    return offset; 
}   
 
public void reset() {
    // The field delivers previous value from the undefinite status
    setPreviousValue(getInitialValue());
    isUndefinedPrevValue = true; 
}
 
public boolean isPMapBitExist() {
    // Increment fields require presence map bit
    return true; 
}   
 
public boolean isFieldNullable() {
    // If isMandatory false the Increment field could has the null
	//representation of field value and does not apear in the output fix message     
    return !isMandatory; 
}