Class DataClassSerializer
java.lang.Object
eu.cloudnetservice.driver.impl.network.object.data.DataClassSerializer
- All Implemented Interfaces:
eu.cloudnetservice.driver.network.object.ObjectSerializer<Object>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.github.benmanes.caffeine.cache.Cache<Class<?>, Tuple2<DataClassCodec, AllocationStatistic>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate @NonNull DataClassCodeccreateDataClassCodec(@NonNull Class<?> targetType) Generates the data class codec for the given target type.private static voidensureClassIsInstantiable(@NonNull Class<?> clazz) Validates that an instance of the given class can be constructed in runtime.read(@NonNull eu.cloudnetservice.driver.network.buffer.DataBuf source, @NonNull Type type, @NonNull eu.cloudnetservice.driver.network.object.ObjectMapper caller) voidMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.object.ObjectSerializer
preReadCheckAccepts, preWriteCheckAccepts
-
Field Details
-
dataClassCodecCache
private final com.github.benmanes.caffeine.cache.Cache<Class<?>, Tuple2<DataClassCodec, AllocationStatistic>> dataClassCodecCache
-
-
Constructor Details
-
DataClassSerializer
public DataClassSerializer()
-
-
Method Details
-
ensureClassIsInstantiable
Validates that an instance of the given class can be constructed in runtime. This means that the class is not abstract, an interface and does not represent a primitive type.- Parameters:
clazz- the class to check.- Throws:
IllegalArgumentException- if the given class is not instantiable.NullPointerException- if the given class is null.
-
read
@NonNull public @NonNull Object read(@NonNull @NonNull eu.cloudnetservice.driver.network.buffer.DataBuf source, @NonNull @NonNull Type type, @NonNull @NonNull eu.cloudnetservice.driver.network.object.ObjectMapper caller) - Specified by:
readin interfaceeu.cloudnetservice.driver.network.object.ObjectSerializer<Object>
-
write
public void write(@NonNull eu.cloudnetservice.driver.network.buffer.DataBuf.Mutable dataBuf, @NonNull @NonNull Object object, @NonNull @NonNull Type type, @NonNull @NonNull eu.cloudnetservice.driver.network.object.ObjectMapper caller) - Specified by:
writein interfaceeu.cloudnetservice.driver.network.object.ObjectSerializer<Object>
-
createDataClassCodec
@NonNull private @NonNull DataClassCodec createDataClassCodec(@NonNull @NonNull Class<?> targetType) Generates the data class codec for the given target type. The result of the method is cached, and should not be called directly due to some heavy work that is required to construct the data class codec.- Parameters:
targetType- the target type to construct the data class codec for.- Returns:
- the generated data class codec for the given target type.
- Throws:
IllegalStateException- if the given target type is missing an all-args constructor.NullPointerException- if the given target type is null.
-