Skip to content

Add copy() to message decoders #966

Closed
@ratcashdev

Description

@ratcashdev

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.

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