-
-
Notifications
You must be signed in to change notification settings - Fork 840
Add ConcurrentHashMap.KeySetView serializer #1183
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 ConcurrentHashMap.KeySetView serializer #1183
Conversation
test/com/esotericsoftware/kryo/serializers/CollectionSerializerTest.java
Outdated
Show resolved
Hide resolved
4d8c1ca to
0d8ff23
Compare
src/com/esotericsoftware/kryo/serializers/DefaultSerializers.java
Outdated
Show resolved
Hide resolved
0d8ff23 to
1e6f4a3
Compare
1e6f4a3 to
5e8938f
Compare
| /** Serializer for {@link ConcurrentHashMap.KeySetView}. | ||
| * @author Andreas Bergander */ | ||
| public static class KeySetViewSerializer extends CollectionSerializer<ConcurrentHashMap.KeySetView> { | ||
| protected void writeHeader (Kryo kryo, Output output, ConcurrentHashMap.KeySetView set) { |
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.
I just realized that this is not ideal. We are writing the keys twice. Once here as part of the map in the header and then again in the main write method of the CollectionSerializer. It would be enough to write the map because the keyset is only a view. Can you try to implement this without extending CollectionSerializer and implement Serializer directly? This should make the serialized payload significantly smaller.
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.
writeHeader would simply become write and create would become read.
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.
Thank you for pointing me in the right direction! PR is updated according to your comments.
src/com/esotericsoftware/kryo/serializers/DefaultSerializers.java
Outdated
Show resolved
Hide resolved
c23345f to
899dd2d
Compare
899dd2d to
96015bd
Compare
theigl
left a comment
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.
That looks great now, thanks!
This PR adds support for serializing sets created by
ConcurrentHashMap.newKeySet().