GdxToKryo: Future-proof Kryo serialization in LibGDX

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

GdxToKryo: Future-proof Kryo serialization in LibGDX

Postby tenfour04 » Fri Oct 27, 2017 1:39 am

GdxToKryo is my new library for making it easy to use Kryo for serialization with LibGDX. It has built-in serializers for almost any LibGDX class that might be part of data you want to store. This includes almost every class in the utils and math packages, as well as a few graphics classes, like Pixmap, Color, and the cameras.

Dedicated serializers are better than FieldSerializer because they can store the data more efficiently, and they enable backward compatibility. That means if you update to a later version of LibGDX that changes some of the fields in any classes you've saved, you'll still be able to open data saved in older versions of your game. I also included a GraphHeader class that helps manage this, as well as changes you've made to your own classes.

I made this library because I'm working on a big app that saves a large, complex object graph full of lots of LibGDX classes, and I was concerned about maintaining backward compatibility.

Forward compatibility cannot be promised, but I'll aim to add notices if forward compatibility becomes broken for any classes. It's probably safest to avoid assuming it can be maintained for the LibGDX classes. I reserved an extra byte in some of the generic collections' serializers because I suppose there's a possibility of them gaining type-awareness like Array has, so those are likely safe. I suggest using the GraphHeader to allow forward compatibility as long as the LibGDX version matches, and show users an incompatibility message otherwise.

Even if you don't care about the backward compatibility stuff, the PixmapSerializer might come in handy. And the dedicated serializers offer savings in data size if you're using Kryo-net (which I've never used).

I was waiting for the 1.9.7 release of LibGDX to give this an official release, since there were a couple of utility/math classes that needed some fixes to make them cleanly serializeable.

I have tested this only with unit tests and ruidmentary saves in my own project that uses it. Please make sure to test thoroughly if you plan to use it in a released product. As I get closer to completing testing of my own project, I'll have more confidence in the robustness of this library.
Posts: 1186
Joined: Sat Jun 18, 2011 3:24 pm

Re: GdxToKryo: Future-proof Kryo serialization in LibGDX

Postby TypeOverride » Wed Nov 22, 2017 11:14 pm

Why not directly using the Kryo Serializer in a project?

compile 'com.esotericsoftware:kryo:4.0.1'

What has Gdx to do with it?
Posts: 101
Joined: Fri Apr 05, 2013 1:11 pm

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest