Table of contents

 

This operator instructs the decoder to use the previous value if the value is not present in the encoded message (PMap bit is not set).
Here's the decoding algorithm of these fields:

Decoding algorithm of fields with Copy Operator

Picture 3.10 - "Decoding algorithm of fields with Copy Operator"

Code example 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);
        } else {
            if (isMandatory) {
                throw new RuntimeException(
                    "Mandatory field decoded value can not be NULL");
            } else {
                setPreviousValue(null);
            }
        }
    } else {
        // there is no undefinite status for the previous value
        Object prevValue = getPreviousValue();
        if (prevValue != null) {
            // add field into the message
            message.addValue(tagId, prevValue);
        } 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());
}
 
public boolean isPMapBitExist() {
    // Copy fields require presence map bit
    return true;
}
 
public boolean isFieldNullable() {
    // If isMandatory false the Copy field could has the null representation
    //of field value and does not apear in the output FIX message
    return !isMandatory;
}