Class KryoUtils

java.lang.Object
uno.anahata.ai.internal.KryoUtils

public class KryoUtils extends Object
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 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

      public static byte[] serialize(Object object)
      Serializes an object into a byte array.
      Parameters:
      object - The object to serialize.
      Returns:
      The serialized byte array.
    • deserialize

      public static <T> T deserialize(byte[] bytes, Class<T> clazz)
      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.