Class KryoUtils
java.lang.Object
uno.anahata.ai.internal.KryoUtils
Utility class for high-performance object serialization using the Kryo library.
This class is primarily used for saving and loading conversation history.
It uses a ThreadLocal to manage Kryo instances, ensuring thread safety
while avoiding the overhead of frequent instance creation.
It pre-registers common Gemini API types and JDK/Guava collections to optimize the serialized output size.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tdeserialize(byte[] bytes, Class<T> clazz) Deserializes an object from a byte array.static com.esotericsoftware.kryo.KryogetKryo()Gets the Kryo instance associated with the current thread.static byte[]Serializes an object into a byte array.
-
Constructor Details
-
KryoUtils
public KryoUtils()
-
-
Method Details
-
getKryo
public static com.esotericsoftware.kryo.Kryo getKryo()Gets the Kryo instance associated with the current thread.- Returns:
- The thread-local Kryo instance.
-
serialize
Serializes an object into a byte array.- Parameters:
object- The object to serialize.- Returns:
- The serialized byte array.
-
deserialize
Deserializes an object from a byte array.- Type Parameters:
T- The expected type of the object.- Parameters:
bytes- The serialized byte array.clazz- The class of the expected type.- Returns:
- The deserialized object.
-
