real-logic / simple-binary-encoding

Simple Binary Encoding (SBE) - High Performance Message Codec
Apache License 2.0
3.08k stars 519 forks source link

XML: Sharing common messages (not just types) into multiple XML #721

Closed Zendarq closed 4 years ago

Zendarq commented 4 years ago

Is there a way to share a common set of sbe:message using ?

In the NASDAQ protocols, the ITCH, NBBO, LastSale protocol messages have common symbology spin messages.

I wanted to see if I can use a common sbe:message definition and then include that within each of the protocol specs.

Is this possible?

mjpt777 commented 4 years ago

Yes. You can see the use of include in the following samples.

https://github.com/real-logic/simple-binary-encoding/blob/master/sbe-samples/src/main/resources/common-types.xml

https://github.com/real-logic/simple-binary-encoding/blob/master/sbe-samples/src/main/resources/example-schema.xml#L10

Zendarq commented 4 years ago

I can do that with types yes but in your common-types.xml

Can I include something like below within the common-types.xml so that this message can be shared among other schemas?

<sbe:message name="Car" id="1" description="Description of a basic Car">
        <field name="serialNumber" id="1" type="uint64"/>
        <field name="modelYear" id="2" type="ModelYear"/>
        <field name="available" id="3" type="BooleanType"/>
        <field name="code" id="4" type="Model"/>
        <field name="someNumbers" id="5" type="someNumbers"/>
        <field name="vehicleCode" id="6" type="VehicleCode"/>
        <field name="extras" id="7" type="OptionalExtras"/>
        <field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C"/>
        <field name="engine" id="9" type="Engine"/>
        <group name="fuelFigures" id="10" dimensionType="groupSizeEncoding">
            <field name="speed" id="11" type="uint16"/>
            <field name="mpg" id="12" type="float"/>
            <data name="usageDescription" id="200" type="varStringEncoding"/>
        </group>
        <group name="performanceFigures" id="13" dimensionType="groupSizeEncoding">
            <field name="octaneRating" id="14" type="Ron"/>
            <group name="acceleration" id="15" dimensionType="groupSizeEncoding">
                <field name="mph" id="16" type="uint16"/>
                <field name="seconds" id="17" type="float"/>
            </group>
        </group>
        <data name="manufacturer" id="18" type="varStringEncoding"/>
        <data name="model" id="19" type="varStringEncoding"/>
        <data name="activationCode" id="20" type="varAsciiEncoding"/>
    </sbe:message>
mjpt777 commented 4 years ago

Yes. You need to get the XML and namespacing correct. This is more an XML than an SBE issue.

njustzsm commented 4 years ago

can you offer an example?? I also want to add a message to the common xml,thank you~

mjpt777 commented 4 years ago

Create a file common-msg.xml

<?xml version="1.0" encoding="UTF-8"?>
<sbe:message xmlns:sbe="http://fixprotocol.io/2016/sbe"
    name="Bar" id="2" description="Description of Bar">
    <field name="foo" id="1" type="uint64"/>
</sbe:message>

Then include it in the target.

<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
                   xmlns:xi="http://www.w3.org/2001/XInclude"
                   package="baseline"
                   id="1"
                   version="0"
                   semanticVersion="5.2"
                   description="Example base schema which can be extended."
                   byteOrder="littleEndian">
    <xi:include href="common-types.xml"/>
 ...
    <sbe:message name="Car" id="1" description="Description of a basic Car">
        <field name="serialNumber" id="1" type="uint64"/>
        <field name="modelYear" id="2" type="ModelYear"/>
        <field name="available" id="3" type="BooleanType"/>
        <field name="code" id="4" type="Model"/>
        <field name="someNumbers" id="5" type="someNumbers"/>
        <field name="vehicleCode" id="6" type="VehicleCode"/>
        <field name="extras" id="7" type="OptionalExtras"/>
        <field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C"/>
        <field name="engine" id="9" type="Engine"/>
        <group name="fuelFigures" id="10" dimensionType="groupSizeEncoding">
            <field name="speed" id="11" type="uint16"/>
            <field name="mpg" id="12" type="float"/>
            <data name="usageDescription" id="200" type="varAsciiEncoding"/>
        </group>
        <group name="performanceFigures" id="13" dimensionType="groupSizeEncoding">
            <field name="octaneRating" id="14" type="Ron"/>
            <group name="acceleration" id="15" dimensionType="groupSizeEncoding">
                <field name="mph" id="16" type="uint16"/>
                <field name="seconds" id="17" type="float"/>
            </group>
        </group>
        <data name="manufacturer" id="18" type="varStringEncoding"/>
        <data name="model" id="19" type="varStringEncoding"/>
        <data name="activationCode" id="20" type="varAsciiEncoding"/>
    </sbe:message>
    <xi:include href="common-msg.xml"/>
</sbe:messageSchema>