FIXTradingCommunity / fix-simple-binary-encoding

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

Use of <ref> to refer a nested composite type. #123

Open cardefusco opened 4 years ago

cardefusco commented 4 years ago

My question is, referring to SBE 2.x, if is possible to use the <ref> tag to link to a composite type that was just defined as a nested composite. I try to explain it with an example. Imagine that I have this:

<composite name="longPrice">
    <type name="mantissa" primitiveType="int64" />
    <type name="exponent" primitiveType="int8" />
    <composite name="priceType">
        <type name="internalPriceCode" primitiveType="char" length="3"/>
        <enum name="enumPriceCode" encodingType="uint8">
            <validValue name="USD">0</validValue> 
            <validValue name="EUR">1</validValue>
        </enum>
    </composite>    
</composite>    

<composite name="shortPrice">
    <type name="mantissa" primitiveType="int32" />
    <type name="exponent" primitiveType="int8" />
    <ref name="priceTypeRef" type="priceType" offset="5" />
</composite>    

Technically the XSD of version 2.x allows this. So is this correct? Could I use a <ref> tag in this way where the composite "priceType" is referred despite is nested definition?

I think that however is desiderable and maybe better to have this solution, right?:

<composite name="priceType">
    <type name="internalPriceCode" primitiveType="char" length="3"/>
    <enum name="enumPriceCode" encodingType="uint8">
        <validValue name="USD">0</validValue> 
        <validValue name="EUR">1</validValue>
    </enum>
</composite>

<composite name="longPrice">
    <type name="mantissa" primitiveType="int64" />
    <type name="exponent" primitiveType="int8" />
    <ref name="priceTypeRef" type="priceType" offset="9" />
</composite>    

<composite name="shortPrice">
    <type name="mantissa" primitiveType="int32" />
    <type name="exponent" primitiveType="int8" />
    <ref name="priceTypeRef" type="priceType" offset="5" />
</composite>    
donmendelson commented 4 years ago

The specification says that the type attribute of <ref> ...

Must match a defined type, enum or set or composite name attribute.

It seems to me that your second example is in line with the intent of the specification.

cardefusco commented 4 years ago

Ok. Could be useful, I think, to refer a nested composite using "." to concatenate the nested composite. In this way I can write longPrice.priceTypeRef For example, referring to my first example I could write:

<ref name="longPrice.priceTypeRef" type="priceType" offset="5" />

This could be an idea to avoid ambiguous interpretation, even if I prefer my second example above where there is not a referring to a nested composite.