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 helpers for serializing collections #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tmr232
Copy link

@tmr232 tmr232 commented Jan 27, 2021

This is a class of helper functions we use when serializing collections.
It takes care of the index manipulation and assures the user that this is only serialization - not a generic loop.

Without the helpers:

var thingsBuilder = builder.initThings(items.size());
for (int i = 0; i < items.size(); ++i) {
    var thingBuilder = thingsBuilder.get(i);
    var item = items.get(i);
    thingBuilder.setAttr(item.getAttr());
    thingBuilder.setOther(item.getOther());
}

With the helpers:

serializeCollection(
    items, builder::initThings,
    (item, thingBuilder) -> {
        thingBuilder.setAttr(item.getAttr());
        thingBuilder.setOther(item.getOther());
    }
);

@dwrensha
Copy link
Member

dwrensha commented Feb 1, 2021

Thanks!

I think using the word serialize in the names of these functions clashes somewhat with the rest of capnproto-java, where "serialize" means to go from a MessageBuilder to bytes.

I don't have a good sense for how generally useful these new functions are. It would help if they had some documentation comments and possibly some tests.

@tmr232
Copy link
Author

tmr232 commented Feb 1, 2021

What do you think would be a good name, then?

And anything specific you'd like to see in the test, or just a comparison against the regular-loop version to see that it is equivalent?

@dwrensha
Copy link
Member

dwrensha commented Feb 9, 2021

What do you think would be a good name, then?

I don't have any suggestions, because I don't have a good sense for the situations in which these functions are intended to be used.

And anything specific you'd like to see in the test, or just a comparison against the regular-loop version to see that it is equivalent?

Mainly I'm interested in seeing explanations and examples of how these functions are meant to be used.

I'm worried that maybe these functions are too specialized to merit a place in the base library. I was hoping that if you provided more context then I would be able to make a better judgment about that.

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.

2 participants