-
Notifications
You must be signed in to change notification settings - Fork 823
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
ReflectASM doesn't use primitive serializers #149
Comments
Oops. Very good catch! :-) It looks like I forgot during my re-factorings to overload the "write", "read" and "copy" methods for ObjectField when I was defining ObjectField$ObjectIntField and the like. But which behavior do we prefer? The one from AsmCachedField-derived classes or the one from ObjectField-derived classes? I.e. do we want to use a registered serializer for primitive types or directly shortcut it and use output methods for primitive types? I'm in favor of the later more optimized approach. |
The optimized approach is fine until you want to customize the serialization of a primitive type. Maybe you know an int can't be negative or a string (not primitive but handled the same way) is always ASCII. The optimization could be configurable, maybe by using a separate CachedFieldFactory. Actually I see the factory is internal and not configurable. Maybe it should be? It may simplify FieldSerializer if it just has a factory it gets fields from. FieldSerializer wouldn't need to know about ASM/unsafe/etc at all. Also the code for ASM/unsafe/etc would be separated into different factories, which could be nice and tidy. Maybe we should also remove asmEnabled from Kryo? It seems FieldSerializer specific, or, if CachedFieldFactory is made public then it is specific to the CachedFieldFactory implementation. I see CachedFieldFactory is public but should be package private, unless we do the refactoring mentioned. Anyway, maybe we should default to using the serializers, as that seems like the expected behavior, and have the optimization be configurable somehow? What do you think? |
Hmm. You touch on many interesting points.
|
|
But coming back to the original issue:
|
Ping? |
Sorry, missed this one.
|
…work in the same way as AsmCacheField and UnsafeCacheField. All of them optimize for speed and ignore any custom registered serializers for primitive types for now.
Nate, I committed changes that make all FieldSerializer backends behave in the same way, when it comes to serialization of primitive types. So, at least it should be possible now to serialize on desktop and deserialize on Android and vice versa, I hope. Would be nice if you could check it. BTW, can we somehow disable usage of ASM even if it is available and force usage of a reflection-based backend? This would allow us to write unit tests which check ASM, Unsafe and Reflection-based backends. |
Cool, thanks! I don't have a test setup unfortunately, the issue came from a KryoNet user. Disabling ASM could be done by the FieldFactory stuff discussed above. The default factory could choose the actual factory based on what is available, otherwise a user could configure a FieldSerializer to use a ReflectionFieldFactory, for example. |
Closing, reopen if still relevant. |
From here:
https://groups.google.com/forum/#!topic/kryonet-users/AspUPsZcNu0
It seems ObjectField$ObjectIntField uses ObjectField#write/read which uses the registered serializer for primitive int. However AsmCachedField$AsmIntField does not use a serializer. This means something written on the desktop via ASM cannot be read on Android without ASM.
Here is an example:
https:/EsotericSoftware/kryonet/blob/master/src/com/esotericsoftware/kryonet/rmi/ObjectSpace.java#L594
ObjectField#write will use this serializer, AsmIntField#read won't.
The text was updated successfully, but these errors were encountered: