FIXTradingCommunity / fix-simple-binary-encoding

A FIX standard for binary message encoding
Other
262 stars 69 forks source link

How to create a fixed array of a composite? #115

Open lygstate opened 4 years ago

donmendelson commented 4 years ago

The standard way to create an array of records in SBE is to define a repeating group. A field in the group could have a composite encoding. The number of entries in a group can be restricted using minValue or maxValue on the group counter numInGroup of group dimensions. By setting both attributes, a group can be constrained to a fixed size.

lygstate commented 4 years ago

even thout minValue maxValue are equal can resolve the issue, but a new problem arising, I won't the encoded SBE buffer are fixed size and are pre-know, by using group that would make the size can not be pre-know

kleihan commented 4 years ago

A general comment: SBE was intended to be primarily a binary, fixed-length encoding for high performance. Using repeating groups should be an exception and is a trade-off between bandwidth consumption and speed. If you set the number of elements to a single value and each element to a fixed size as well, then the meta-data should give you the length of the message. A recommendation is also to have only one repeating group per message in your design and to put that at the end of the message, for example partial order executions or leg-level executions of an order.

lygstate commented 4 years ago
    <types>
        <enum name="OrderSide" encodingType="uint8">
            <validValue name="buy">0</validValue>
            <validValue name="sell">1</validValue>
        </enum>
        <enum name="OrderType" encodingType="uint8">
            <validValue name="market">0</validValue>
            <validValue name="limit">1</validValue>
            <validValue name="stop">2</validValue>
        </enum>
        <composite name="order">
            <type name="id" primitiveType="int32"/>
            <type name="symbol" primitiveType="char" length="10" characterEncoding="UTF-8"/>
            <ref name="side" type="OrderSide"/>
            <ref name="type" type="OrderType"/>
            <type name="price" primitiveType="double"/>
            <type name="volume" primitiveType="double"/>
        </composite>
        <composite name="ordersWithoutLength" arrayCapacity="3">
            <ref name="data" type="order"/>
        </composite>
        <composite name="ordersWithLengthAtBegin" arrayCapacity="3">
            <type name="length" primitiveType="uint8"/>
            <ref name="data" type="order"/>
        </composite>
        <composite name="ordersWithLengthAtEnd" arrayCapacity="3">
            <ref name="data" type="order"/>
            <type name="length" primitiveType="uint8" length="1"/>
        </composite>
    </types>

I suggest add Array Composite type