Class ConfiguredCodec<C,O>

java.lang.Object
net.luis.utils.io.codec.ConfiguredCodec<C,O>
Type Parameters:
C - The type of the component
O - The type of the object

public class ConfiguredCodec<C,O> extends Object
A codec that is configured to encode and decode a specific component of an object.
This codec uses another codec to encode and decode the component.
The underlying codec is expected to be an instance of NamedCodec.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Codec<C>
    The codec used to encode and decode the component.
    private final Function<O,C>
    The function used to retrieve the component from the object.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConfiguredCodec(@NotNull Codec<C> codec, @NotNull Function<O,C> getter)
    Constructs a new configured codec using the given codec and getter for the component.
  • Method Summary

    Modifier and Type
    Method
    Description
    <R> @NotNull Result<C>
    decodeStart(@NotNull TypeProvider<R> provider, R value)
    Decodes the component of the object using the given type provider and value.
    This method will simply pass through the value to the underlying codec.
    <R> @NotNull Result<R>
    encodeStart(@NotNull TypeProvider<R> provider, R current, O object)
    Encodes the component of the object using the given type provider and current value.
    boolean
     
    int
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • codec

      private final Codec<C> codec
      The codec used to encode and decode the component.
    • getter

      private final Function<O,C> getter
      The function used to retrieve the component from the object.
  • Constructor Details

    • ConfiguredCodec

      ConfiguredCodec(@NotNull @NotNull Codec<C> codec, @NotNull @NotNull Function<O,C> getter)
      Constructs a new configured codec using the given codec and getter for the component.
      Parameters:
      codec - The codec
      getter - The getter
      Throws:
      NullPointerException - If the codec or getter is null
  • Method Details

    • encodeStart

      @NotNull public <R> @NotNull Result<R> encodeStart(@NotNull @NotNull TypeProvider<R> provider, @NotNull R current, @Nullable O object)
      Encodes the component of the object using the given type provider and current value.
      Type Parameters:
      R - The type of the current value
      Parameters:
      provider - The type provider
      current - The current value
      object - The object
      Returns:
      The result of the encoding operation
      Throws:
      NullPointerException - If the type provider or current value is null
    • decodeStart

      @NotNull public <R> @NotNull Result<C> decodeStart(@NotNull @NotNull TypeProvider<R> provider, @Nullable R value)
      Decodes the component of the object using the given type provider and value.
      This method will simply pass through the value to the underlying codec.
      Type Parameters:
      R - The type of the value
      Parameters:
      provider - The type provider
      value - The value
      Returns:
      The result of the decoding operation
      Throws:
      NullPointerException - If the type provider is null
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object