Skip to content

Conversation

zyulyaev
Copy link
Contributor

This PR allows to set ASCII encoded char array fields with any class implementing CharSequence, not only with Strings. It helps writing GC-free code without handling byte arrays. One for example can pass StringBuilder as an argument which can be shared between invocations.

@tmontgomery tmontgomery merged commit d6dfb92 into aeron-io:master Mar 19, 2018
@juddgaddie
Copy link
Contributor

@zyulyaev is there any reason why you did not include something similar on the Decoder side that takes an Appendable such as StringBuilder
eg
public void getMyValue(Appendable val)

@zyulyaev
Copy link
Contributor Author

@juddgaddie not really, I just added only what I needed.
Regarding Appendable to Decoder, I would rather added a method that returns a wrapper object implementing CharSequence interface, similar to how currently composite decoders work.
eg

private final MyValueWrapper myValueWrapper = new MyValueWrapper();

public CharSequence myValueWrapper() {
    return myValueWrapper;
}

private class MyValueWrapper implements CharSequence {
    public int length() {
        int len;
        for (len = 0; charAt(len) != 0; len++);
        return len;
    }

    public char charAt(int index) {
        final int pos = this.offset + <offset> + index;
        return (char) buffer.getByte(pos);
    }
}

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

Successfully merging this pull request may close these issues.

3 participants