objectcomputing / mFAST

A FAST (FIX Adapted for STreaming) encoder/decoder
http://objectcomputing.github.io/mFAST
BSD 3-Clause "New" or "Revised" License
224 stars 112 forks source link

Constant sequence length fix #113

Closed a-dmitrovsky-db closed 3 years ago

a-dmitrovsky-db commented 3 years ago

This fixes error which occurs when parsing Eurex messages with mFAST.

Eurex schema uses constant length sequences in several places, e.g. in QuoteRequest message:

  <sequence name="SequenceGroup">
      <length name="NoElements" id="111">
        <constant value="1"/>
      </length>
      <int64 name="Id" id="112">
        <copy/>
      </int64>
    </sequence>

Unfortunately mFAST fails to properly handle that schema.

The problem boils down to code decoding sequence instruction:

    template <typename T>
    inline void fast_decoder_base::decode_field(const T &ext_ref,
                                                sequence_type_tag) {
      value_storage storage;

      auto length = ext_ref.set_length(storage);
      this->visit(length);

Here value_storage is not initialized with initial (constant) value. Later, in

    template <typename T, typename TypeCategory>
    void fast_decoder_base::decode_field(const T &ext_ref,
                                         constant_operator_tag,
                                         TypeCategory) {

the value for constant field is not copied (and that's what was changed in original patch) and sequence length is considered to be 0 leaving all of sequence payload bytes unparsed.

SBAM commented 3 years ago

Hi, if you're using decoder_v2, you should uncomment the default value setter as per : https://github.com/SBAM/mFAST/commit/a498d40308f1c98ee604986b5c89a71a26d4555f (can't figure out why it was commented in the first place)