Record Class OneOfCodec<T>

java.lang.Object
java.lang.Record
com.github.darksoulq.abyssallib.common.serialization.codecs.OneOfCodec<T>
Type Parameters:
T - Common value type.
All Implemented Interfaces:
Codec<T>

public record OneOfCodec<T>(List<Codec<T>> codecs) extends Record implements Codec<T>
Codec that attempts multiple codecs until one succeeds.
  • Constructor Details

    • OneOfCodec

      public OneOfCodec(List<Codec<T>> codecs)
      Creates a one-of codec.
      Parameters:
      codecs - Candidate codecs evaluated in order.
  • Method Details

    • codecs

      public List<Codec<T>> codecs()
      Returns the available codec branches.
      Returns:
      Immutable codec list.
    • 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 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.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.