Module net.minestom.server
Package net.minestom.server.codec
Interface Decoder<T extends @UnknownNullability Object>
- Type Parameters:
T
- the value type
- All Known Subinterfaces:
Codec<T>
,DataComponent<T>
,StructCodec<R>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Decoders are interfaces used in
For example:
Codec
which purpose is to decode any value of Decoder
with a transcoder.
For example:
record Name(String imTheBoss) { }
Decoder<Name> decoder = new Decoder<>() {
@Override
public <D> Result<Name> decode(Transcoder<D> coder, D value) {
return coder.getString(value).mapResult(Name::new);
}
};
Result<Name> result = decoder.decode(Transcoder.NBT, StringBinaryTag.stringBinaryTag("me")); // Result.OK(Name("me"))
Result<Name> errorResult = decoder.decode(Transcoder.NBT, EndBinaryTag.endBinaryTag()); // Result.Error(...)
-
Method Summary
Modifier and TypeMethodDescriptiondecode
(Transcoder<D> coder, D value) Decodes a value ofDecoder
using the specificTranscoder
TheResult
will be ofResult.Ok
orResult.Error
and its typedDecoder
static <T> Decoder
<T> unit
(T value) Returns a unit decoder of T
-
Method Details
-
unit
Returns a unit decoder of T- Type Parameters:
T
- the type of value- Parameters:
value
- the value to always return- Returns:
- the unit decoder
-
decode
Decodes a value ofDecoder
using the specificTranscoder
TheResult
will be ofResult.Ok
orResult.Error
and its typedDecoder
- Type Parameters:
D
- The value type- Parameters:
coder
- the transcoder to usevalue
- the value to decode- Returns:
- the
Result
of the encoding with its type determined by the transcoder
-