Interface KeyableEncoder<C>

Type Parameters:
C - The type of the value to encode
All Superinterfaces:
Encoder<C>
All Known Subinterfaces:
KeyableCodec<C>
All Known Implementing Classes:
RangeCodec

public interface KeyableEncoder<C> extends Encoder<C>
Extension of Encoder that allows encoding keys.
A key is a string used to identify a value in a data structure.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <R> @NotNull Result<String>
    encodeKey(@NotNull TypeProvider<R> provider, C key)
    Encodes the key of the specified type and returns the encoded key as a result.
    The result contains the encoded key or an error message.
    static <C> @NotNull KeyableEncoder<C>
    of(@NotNull Encoder<C> encoder, @NotNull Function<C,@Nullable String> keyEncoder)
    Creates a new keyable encoder from the specified encoder and key encoder.
    The key encoder function converts a key to a string.
    If the key encoder is not able to handle a key, it can simply return null.

    Methods inherited from interface net.luis.utils.io.codec.encoder.Encoder

    encode, encode, encodeStart, mapEncoder
  • Method Details

    • of

      @NotNull static <C> @NotNull KeyableEncoder<C> of(@NotNull @NotNull Encoder<C> encoder, @NotNull @NotNull Function<C,@Nullable String> keyEncoder)
      Creates a new keyable encoder from the specified encoder and key encoder.
      The key encoder function converts a key to a string.
      If the key encoder is not able to handle a key, it can simply return null.
      Type Parameters:
      C - The type of the value to encode
      Parameters:
      encoder - The encoder
      keyEncoder - The key encoder function
      Returns:
      The keyable encoder
      Throws:
      NullPointerException - If the encoder or the key encoder function is null
    • encodeKey

      @NotNull <R> @NotNull Result<String> encodeKey(@NotNull @NotNull TypeProvider<R> provider, @NotNull C key)
      Encodes the key of the specified type and returns the encoded key as a result.
      The result contains the encoded key or an error message.
      Type Parameters:
      R - The type to encode to
      Parameters:
      provider - The type provider
      key - The key to encode
      Returns:
      The result
      Throws:
      NullPointerException - If the type provider or the key is null