FIXTradingCommunity / fix-simple-binary-encoding

A FIX standard for binary message encoding
Other
253 stars 67 forks source link

Re-reuse of repeating group entries #105

Closed zamhassam closed 5 years ago

zamhassam commented 5 years ago

We would like to share our repeating group definitions across multiple messages. We have tried modelling this as having repeating groups with each having one entry and that entry being a composite, however composites are much more restrictive than repeating groups.

The motivation is we have some shared entities which are present in repeating groups in multiple messages, but currently each one is scoped by its own enclosing message and the same codec is generated multiple times. As a consequence, our application has several areas of duplicated code to deal with several identical codecs.

Related to #47 and #13.

Sample schema to demostrate the idea using a new type called component which should provide the same flexibility as a repeating group (fixed length fields, nested groups, variable length data) to define the structure of a group entry:

<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" byteOrder="littleEndian" description="" id="1" package="" semanticVersion="0.0.1" version="1">
    <types>
        <component id="16" name="marketDataEntry">
            <field name="price" id="17" type="decimalFloat" description=""/>
            <field name="quantity" id="19" type="decimalFloat" description=""/>
            <field name="quantityType" id="20" type="quantityType" description=""/>
            <field name="side" id="21" type="side" description=""/>
            <group>
            </group>
            <data name="referenceId" id="22" type="varStringEncoding" description=""/>
        </component>
    </types>
    <sbe:message id="1" name="MarketDataIncremental" description="">
        <group id="24" name="MarketDataEntries" dimensionType="groupSizeEncoding" component="marketDataEntry"/>
    </sbe:message>
    <sbe:message id="2" name="MarketDataSnapshot" description="">
        <group id="24" name="MarketDataEntries" dimensionType="groupSizeEncoding" component="marketDataEntry"/>
    </sbe:message>
</sbe:messageSchema>
kleihan commented 5 years ago

Summary of discussion of May 8 in HPWG conference call:

donmendelson commented 5 years ago

Let's assume that the boundaries of a component block such as Instrument are respected. Then, a component is the same thing as a repeating group, except that the numInGroup is always 1, or perhaps zero if the component is optional. Like a repeating group, it would support extension and could include nested groups and var length fields. To support extension, you must send blockLength on the wire, so we might as well keep the dimension header the same format as for a repeating group, except that the numInGroup element is constrained by maxValue, an attribute that already exists.

<composite name="componentSizeEncoding">
    <type name="blockLength" primitiveType="uint16"/>
    <type name="numInGroup" primitiveType="uint16" maxValue="1"/>
    <type name="numGroups" primitiveType="uint16"/>
    <type name="numVarDataFields" primitiveType="uint16"/>
</composite>
mjpt777 commented 5 years ago

This could be difficult to implement efficiently. An alternative which would be to allow a repeating group to contain another message. Allowing a message to contain a repeating group of messages is more like other type systems and composable. I'd be tempted to not add this to the specification without prototyping to get a better understanding of the consequences.

juddgaddie commented 5 years ago

After a discussion with @zamhassam we agree with Martin's assessment and are happy for this issue to be closed until we are able to get an indication of its implementation viability, if we are able to prototype a viable solution we will submit a new issue with the details.