Class UnitCodec<T>

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.codecs.UnitCodec<T>
Type Parameters:
T - Value type.
All Implemented Interfaces:
Codec<T>

public class UnitCodec<T> extends Object implements Codec<T>
Codec that always decodes to a predefined value and encodes to an empty representation.
  • Constructor Details

    • UnitCodec

      public UnitCodec(Supplier<T> value)
      Creates a unit codec.
      Parameters:
      value - Supplier providing the constant value.
  • Method Details

    • decode

      public <D> DataResult<T> decode(DynamicOps<D> ops, D input)
      Description copied from interface: Codec
      Decodes a serialized input of a specific data format into a Java object.
      Specified by:
      decode in interface Codec<T>
      Type Parameters:
      D - The type of the serialized data.
      Parameters:
      ops - The provider defining how to navigate and read data of type D.
      input - The raw serialized input to be processed.
      Returns:
      A DataResult containing the decoded object or an error state.
    • encode

      public <D> DataResult<D> encode(DynamicOps<D> ops, T val)
      Description copied from interface: Codec
      Encodes a Java object into its serialized representation.
      Specified by:
      encode in interface Codec<T>
      Type Parameters:
      D - The target type of the serialized data.
      Parameters:
      ops - The provider defining how to construct data of type D.
      val - The Java object instance to be serialized.
      Returns:
      A DataResult containing the serialized data or an error state.
    • describe

      public String describe()
      Description copied from interface: Codec
      Outputs a structural description of the expected format for this codec. Useful for schema generation and validation debugging.
      Specified by:
      describe in interface Codec<T>
      Returns:
      The schema definition representing the target type.
    • accept

      public <R> R accept(CodecVisitor<R> visitor)
      Description copied from interface: Codec
      Routes this instance into the visitor API to construct contextual schema layouts.
      Specified by:
      accept in interface Codec<T>
      Type Parameters:
      R - The layout target natively returning explicitly mapped variants.
      Parameters:
      visitor - The evaluation logic instance.
      Returns:
      Evaluated variant functionally extracting outputs.