Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust generator: invalid codegen for composite with sinceVersion #972

Closed
injecto opened this issue Feb 13, 2024 · 4 comments
Closed

Rust generator: invalid codegen for composite with sinceVersion #972

injecto opened this issue Feb 13, 2024 · 4 comments

Comments

@injecto
Copy link

injecto commented Feb 13, 2024

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
Copy link
Contributor

mjpt777 commented Feb 14, 2024

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

@mward
Copy link
Contributor

mward commented Mar 12, 2024

@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
Copy link
Contributor

mward commented Mar 15, 2024

FYI - I've started looking into this

mward pushed a commit to mward/simple-binary-encoding that referenced this issue Mar 21, 2024
vyazelenko pushed a commit that referenced this issue Mar 21, 2024
…solve Issue #972 (#981)

Co-authored-by: Michael Ward <mward@drw.com>
@vyazelenko
Copy link
Contributor

Fixed with #981

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants