mFAST icon indicating copy to clipboard operation
mFAST copied to clipboard

Parsing enum fields with name not a number - FAST v1.2

Open benjaminfaul2 opened this issue 5 years ago • 3 comments

Hello, I am trying to use mFAST with FAST v1.2 templates and it seems to throw a static error when an enum type has element names that are not numbers. E.g.

<define name="Answer">
    <enum>
      <element name="N" id="No"/>
      <element name="Y" id="Yes"/>
    </enum>
  </define>

Is there a way I can fix this? I'm trying to understand the code but it just seems to assume the element names must be a number.

Error:

Throw in function virtual void mfast::xml_parser::field_builder::visit(const mfast::enum_field_instruction*, void*)
Dynamic exception type: boost::exception_detail::clone_impl<mfast::fast_static_error>
std::exception::what: std::exception
[mfast::xml_parser::tag_value*] = 0
[mfast::tag_error_code*] = Unrecognized enum initial value :

Note: I am using the latest master as of 9-Sept-2019. Thanks

benjaminfaul2 avatar Sep 10 '19 00:09 benjaminfaul2

After further digging it appears that later in the template file, a message is defined using this value but with a default that doesn't correspond to any of the named values. E.g

<template id="123" name="ReplyMessage">
    <field name="ReplyAnswer" id="1234" presence="optional">
        <type name="Answer">
            <default value="0"/>
        </type>
    </field>
</template>

Is this invalid syntax?

Thanks

benjaminfaul2 avatar Sep 10 '19 03:09 benjaminfaul2

It seems the mFAST implementation of handling the default enum value is incorrect. See this link:

https://forum.fixtrading.org/t/default-value-for-enumeration-fast-1-2-extension/1236/2

The default value is the "on the wire" value not a enum field name.

benjaminfaul2 avatar Sep 11 '19 22:09 benjaminfaul2

Hi, if you're interested, I addressed this in this fork https://github.com/SBAM/mFAST/commit/4a427bddadaf44f06b00ba42d9d3994cd4ab4ac4 If an id attribute is provided and matches, it will be selected, otherwise it falls back to the name attribute.

SBAM avatar Nov 24 '21 14:11 SBAM