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 implement Codec.
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 Details

    • CodecPair

      public CodecPair(Class<T> target, C codec)
      Constructs a new CodecPair with the given target type and codec.
      Parameters:
      target - The target type the codec supports.
      codec - The codec instance.
  • Method Details

    • canCodecType

      public boolean canCodecType(Class<?> type)
      Determines whether the given type can be handled by this codec.
      Parameters:
      type - The type to check.
      Returns:
      true if the codec supports or is assignable from the given type, otherwise false.
    • asCodecSubtype

      public Class<? extends T> asCodecSubtype(Class<?> type)
      Casts the given type to a subclass of the target type.
      Parameters:
      type - The type to cast.
      Returns:
      The casted class.
      Throws:
      ClassCastException - if type is not a subclass of the target.
    • getTarget

      public Class<T> getTarget()
      Returns the target type of this codec pair.
      Returns:
      The target class.
    • getCodec

      public C getCodec()
      Returns the codec associated with this pair.
      Returns:
      The codec instance.