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 T
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 ofDusing the specificTranscoder
TheResultwill be ofResult.OkorResult.Errorand its typedTstatic <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 ofDusing the specificTranscoder
TheResultwill be ofResult.OkorResult.Errorand its typedT- Type Parameters:
D- The value type- Parameters:
coder- the transcoder to usevalue- the value to decode- Returns:
- the
Resultof the encoding with its type determined by the transcoder
-