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

Add copy() to message decoders #966

Open
ratcashdev opened this issue Jan 15, 2024 · 3 comments
Open

Add copy() to message decoders #966

ratcashdev opened this issue Jan 15, 2024 · 3 comments

Comments

@ratcashdev
Copy link
Contributor

ratcashdev commented Jan 15, 2024

Flyweights are mutable by nature. However, sometimes it is quite handy to make them 'frozen' or immutable.

For this reason, we could be adding a method like copy() like below to the SBE (JAVA) generator template and to agrona's MessageDecoderFlyweight interface:

public <T extends MessageDecoderFlyweight> T copy() {
    int version = this.actingVersion();
    int blockLength = this.actingBlockLength();
    sbeSkip();
    final int length = this.encodedLength();
    sbeRewind();
    final var dst = new ExpandableArrayBuffer(length);
    dst.putBytes(0, this.buffer(), this.offset(), length);
    return new (class).wrap(dst, 0, blockLength, version);
  }

Volunteering for a PR, if this gets accepted.

@mjpt777
Copy link
Contributor

mjpt777 commented Jan 18, 2024

This is a copy of the decoder and the underlying buffer. To be more in keeping with the SBE design it would makes sense to provide a decoder and buffer as a destination.

We have an upcoming feature to have DTOs created from codecs that may be more appropriate.

@ratcashdev
Copy link
Contributor Author

ratcashdev commented Jan 18, 2024

To be more in keeping with the SBE design it would makes sense to provide a decoder and buffer as a destination.

.. or have both options available. Assuming such a copy(...) method was exposed by the MessageDecoderFlyweight interface, it would make creating copies on interface level a tad difficult - it would mean new instances would need to be created through reflection, cough, cough.

ad DTO: sounds interesting. Is there an issue for this?

@mjpt777
Copy link
Contributor

mjpt777 commented Jan 18, 2024

This will also be done for Java. #957

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

2 participants