Skip to content

[Rust] cumulate offset of header and message_header_codec::ENCODED_LENGTH in generated Decoder::header method #987

Closed
@wbprime

Description

@wbprime

Code generator for rust would generate a header method for Decoder (see following)

impl<'a> DonotUsePlaceHolderDecoder<'a> {
        pub fn wrap(
            mut self,
            buf: ReadBuf<'a>,
            offset: usize,
            acting_block_length: u16,
            acting_version: u16,
        ) -> Self {
            let limit = offset + acting_block_length as usize;
            self.buf = buf;
            self.initial_offset = offset;
            self.offset = offset;
            self.limit = limit;
            self.acting_block_length = acting_block_length;
            self.acting_version = acting_version;
            self
        }

        #[inline]
        pub fn encoded_length(&self) -> usize {
            self.limit - self.offset
        }

        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>) -> Self {
            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
            let acting_block_length = header.block_length();
            let acting_version = header.version();

            self.wrap(
                header.parent().unwrap(),
                message_header_codec::ENCODED_LENGTH,
                acting_block_length,
                acting_version,
            )
        }
}

The header method take a header decoder and call wrap method, passing message_header_codec::ENCODED_LENGTH as offset.

Considering a header decoder may be wraped with a none-zero offset header_off, header method should wrap with header_off + message_header_codec::ENCODED_LENGTH. To support this functionality, a MessageHeaderDecoder should expose its offset via, say get_limit() or something else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions