-
Notifications
You must be signed in to change notification settings - Fork 36
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
[#416] Add support for Stream and Iterable to @ProtoField #417
[#416] Add support for Stream and Iterable to @ProtoField #417
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@wburns do you wanna take a look too? |
It looks good to me in general. My only main concern is I don't know if I like the idea of Stream being marshalled. A Stream instance is inherently meant to only be used once, so I worry this can lead to misuse in some way. But if we want to keep it knowing that, I won't say no. |
My thinking was that the Stream would only be consumed once when unmarshalling either by the setter or |
It adds value supporting I don't expect users to use |
Never know, if you allow it, some may 😢 But maybe just document that users shouldn't would be sufficient to me. |
Also one thing to note regarding Stream when I checked the generated code is on the unmarshalling side we still create an ArrayList and write into it and then pass the Stream which many times still copies the value into another ArrayList. So while it may save space on the marshalling side it can incur additional overhead on the unmarshalling side. |
Do you mean when a user explicitly creates another list when consuming the stream, or an internal op of the stream? The primary use-case for consuming a Stream like this in Infinispan is for when we're either returning some entries which first need tranformation before they can be marshalled, or Arrays. With the latter, we can't avoid converting from a List to an array due to the way the marshaller reads repeated fields individually from the InputStream and us not knowing the number of entries, but having the Stream allows the consuming |
can we make the generator code to check @wburns I'm expecting that public List<UUID> uuids;
@ProtoField(1)
public Stream<String> getStrings() {
return uuids.stream().map(UUID::toString);
}
public void setStrings(Stream<String> strings) {
this.uuids = strings.map(UUID::fromString).toList();
} A more real-world example is to get rid of this "not so great" code: |
Okay, I think I understand. My problem was I was looking at the test classes that are using Iterable and Stream and they are not good usages of Stream marshalling. I wonder if we should just tweak the tests to be more indicative of the desired use case? The only other thing I would recommend is to use a |
Actually |
I guess we can integrate it as is. We can always change as needed later. |
Closes #416