Package org.caffinitas.ohc
Interface CacheSerializer<T>
-
public interface CacheSerializer<T>
Serialize and deserialize cached data usingByteBuffer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
deserialize(ByteBuffer buf)
Deserialize from the specifiedDataInput
instance.void
serialize(T value, ByteBuffer buf)
Serialize the specified type into the specifiedByteBuffer
instance.int
serializedSize(T value)
Calculate the number of bytes that will be produced byserialize(Object, java.nio.ByteBuffer)
for given objectt
.
-
-
-
Method Detail
-
serialize
void serialize(T value, ByteBuffer buf)
Serialize the specified type into the specifiedByteBuffer
instance.- Parameters:
value
- non-null
object that needs to be serializedbuf
-ByteBuffer
into which serialization needs to happen.
-
deserialize
T deserialize(ByteBuffer buf)
Deserialize from the specifiedDataInput
instance.Implementations of this method should never return
null
. Although there might be no explicit runtime checks, a violation would break the contract of several API methods inOHCache
. For example users ofOHCache.get(Object)
might not be able to distinguish between a non-existing entry or the "value"null
. Instead, consider returning a singleton replacement object.- Parameters:
buf
-ByteBuffer
from which deserialization needs to happen.- Returns:
- the type that was deserialized. Must not return
null
.
-
serializedSize
int serializedSize(T value)
Calculate the number of bytes that will be produced byserialize(Object, java.nio.ByteBuffer)
for given objectt
.- Parameters:
value
- non-null
object to calculate serialized size for- Returns:
- serialized size of
t
-
-