- Type Parameters:
C
- The type of the value to encode
- All Superinterfaces:
Encoder<C>
- All Known Subinterfaces:
KeyableCodec<C>
- All Known Implementing Classes:
RangeCodec
Extension of
A key is a string used to identify a value in a data structure.
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 TypeMethodDescriptionencodeKey
(@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> 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 encoderkeyEncoder
- 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 providerkey
- The key to encode- Returns:
- The result
- Throws:
NullPointerException
- If the type provider or the key is null
-