Class CodecPair<T,C extends Codec<?,?>>
java.lang.Object
de.craftsblock.craftsnet.api.codec.CodecPair<T,C>
- Type Parameters:
T- The target type the codec supports.C- The codec type, which must implementCodec.
- Direct Known Subclasses:
DecoderPair,EncoderPair
@Experimental
public abstract sealed class CodecPair<T,C extends Codec<?,?>>
extends Object
permits DecoderPair<T>, EncoderPair<T>
A sealed base class representing a binding between a target type and a corresponding codec.
This class is extended by DecoderPair and EncoderPair to handle specific
codec types. It provides utility methods to validate and adapt target types.
- Since:
- 3.5.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasCodecSubtype(Class<?> type) Casts the given type to a subclass of the target type.booleancanCodecType(Class<?> type) Determines whether the given type can be handled by this codec.getCodec()Returns the codec associated with this pair.Returns the target type of this codec pair.
-
Constructor Details
-
CodecPair
Constructs a newCodecPairwith the given target type and codec.- Parameters:
target- The target type the codec supports.codec- The codec instance.
-
-
Method Details
-
canCodecType
Determines whether the given type can be handled by this codec.- Parameters:
type- The type to check.- Returns:
trueif the codec supports or is assignable from the given type, otherwisefalse.
-
asCodecSubtype
Casts the given type to a subclass of the target type.- Parameters:
type- The type to cast.- Returns:
- The casted class.
- Throws:
ClassCastException- iftypeis not a subclass of the target.
-
getTarget
Returns the target type of this codec pair.- Returns:
- The target class.
-
getCodec
Returns the codec associated with this pair.- Returns:
- The codec instance.
-