real-logic / simple-binary-encoding

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

Rust generator: invalid codegen for composite with sinceVersion #972

Closed injecto closed 5 months ago

injecto commented 6 months ago

For the sample schema:

<sbe:messageSchema
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:sbe="http://fixprotocol.io/2016/sbe"
    package="test_package"
    id="1"
    version="2"
    semanticVersion="5.0.0"
    byteOrder="littleEndian"
    xsi:schemaLocation="http://fixprotocol.io/2016/sbe sbe.xsd">
    <types>
        <composite name="messageHeader">
            <type name="blockLength" primitiveType="uint16" description="Length of the root of the FIX message contained before repeating groups or variable/conditions fields."/>
            <type name="templateId" primitiveType="uint16" description="Template ID used to encode the message."/>
            <type name="schemaId" primitiveType="uint16" description="ID of the system publishing the message."/>
            <type name="version" primitiveType="uint16" description="Schema version."/>
        </composite>

        <composite name="NewComposite" sinceVersion="1">
            <type name="f1" primitiveType="uint16" presence="optional" nullValue="0" semanticType="Int"/>
            <type name="f2" primitiveType="uint32" presence="optional" nullValue="0" semanticType="Int" offset="4"/>
        </composite>
    </types>
    <sbe:message name="Message" id="1">
        <field name="oldField" id="1" type="uint16" semanticType="Int"/>
        <field name="newField" id="2" type="NewComposite" presence="optional" sinceVersion="1" />
    </sbe:message>
</sbe:messageSchema>

CLI tool 1.30.0 generates Rust code that won't compile with the error:

error[E0609]: no field `acting_version` on type `&new_composite_codec::decoder::NewCompositeDecoder<P>`
   --> test_package/src/new_composite_codec.rs:102:21
    |
102 |             if self.acting_version > 0 && self.acting_version < 1 {
    |                     ^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `parent`, `offset`

The code sample:

        #[inline]
        pub fn f1(&self) -> Option<u16> {
            if self.acting_version > 0 && self.acting_version < 1 {
                return None;

While the decoder struct is

    #[derive(Debug, Default)]
    pub struct NewCompositeDecoder<P> {
        parent: Option<P>,
        offset: usize,
    }
mjpt777 commented 6 months ago

@adam-talos or @mward can you look at this?

mward commented 6 months ago

@adam-talos or @mward can you look at this?

Sorry I didn't see this until today. I'll try to take a look in the next day or two.

mward commented 5 months ago

FYI - I've started looking into this

vyazelenko commented 5 months ago

Fixed with #981