Source code for lmcache.experimental.storage_backend.naive_serde.serde

import abc
from typing import Optional

from lmcache.experimental.memory_management import MemoryObj


[docs] class Serializer(metaclass=abc.ABCMeta):
[docs] @abc.abstractmethod def serialize(self, memory_obj: MemoryObj) -> MemoryObj: """ Serialize/compress the memory object. Input: memory_obj: the memory object to be serialized/compressed. Returns: MemoryObj: the serialized/compressed memory object. """ raise NotImplementedError
[docs] class Deserializer(metaclass=abc.ABCMeta):
[docs] @abc.abstractmethod def deserialize(self, memory_obj: MemoryObj) -> Optional[MemoryObj]: """ Deserialize/decompress the memory object. Input: memory_obj: the memory object to be deserialized/decompressed. Returns: MemoryObj: the deserialized/decompressed memory object. None: if the memory allocation fails. """ raise NotImplementedError