[Java] Generate put CharSequence methods for ASCII encoded fields by zyulyaev · Pull Request #547 · aeron-io/simple-binary-encoding (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation2 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
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.
@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)
@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);
}
}