Class CollectionCodec<T, C extends Collection<T>>

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.codecs.CollectionCodec<T,C>
Type Parameters:
T - Element type.
C - Collection implementation type.
All Implemented Interfaces:
Codec<C>

public class CollectionCodec<T, C extends Collection<T>> extends Object implements Codec<C>
Codec implementation for collection types.
  • Constructor Details

    • CollectionCodec

      public CollectionCodec(Supplier<C> factory, Codec<T> elementCodec, Function<C,C> wrapper)
      Creates a collection codec.
      Parameters:
      factory - Supplier used to create collection instances.
      elementCodec - Codec used for collection elements.
      wrapper - Function applied before returning decoded collections.
  • Method Details

    • decode

      public <D> DataResult<C> 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, C value)
      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.
      value - 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.