java - please provide Kryo code sample - Stack Overflow
Kryo's syntax is relatively similar to java serialisation. A kryo object is created as well as an output/input and one of kryos methods is used to perform the serialisation/deserialisation
kryo.writeClassAndObject(output, object); //for if the concrete class isn't known (can be null)
kryo.writeObjectOrNull(output, someObject); //if the object could be null
kryo.writeObject(output, someObject); //can't be null and concrete class is known
Each of the writes is paired with a read
SomeClass object = (SomeClass)kryo.readClassAndObject(input);
SomeClass someObject = kryo.readObjectOrNull(input, SomeClass.class);
SomeClass someObject = kryo.readObject(input, SomeClass.class);
The following is an example using writeClassAndObject that serialises a Vector3d to a file and back again.
Read full article from java - please provide Kryo code sample - Stack Overflow
No comments:
Post a Comment