Package org.moddingx.libx.codec
Interface TypedEncoder<T,R>
public interface TypedEncoder<T,R>
An encoder that can encode and decode elements of a specific type.
This is used to create type mapped codecs that behave differently depending on the
DynamicOps they are used on.
A TypedEncoder is assumed to be able to encode and decode with every dynamic
ops whose empty element is a subclass of the class returned
by resultClass().-
Method Summary
Modifier and TypeMethodDescriptiondefault <N> TypedEncoder<T, N> cast(com.mojang.serialization.DynamicOps<N> ops) Casts thisTypedEncodergiven someDynamicOps.com.mojang.serialization.DataResult<T> Decodes a value.com.mojang.serialization.DataResult<R> Encodes a value.static <T,R> TypedEncoder <T, R> of(Class<R> resultClass, Function<? super T, ? extends R> encoder, Function<? super R, ? extends T> decoder) Creates a newTypedEncodergiven two functions to encode and decode an object.Gets the class of elements thisTypedEncodercan encode to.
-
Method Details
-
resultClass
Gets the class of elements thisTypedEncodercan encode to. -
encode
Encodes a value. -
decode
Decodes a value. -
cast
Casts thisTypedEncodergiven someDynamicOps. Returnsnullif theTypedEncodercan't be used on the givenDynamicOps. This can be overridden to better whichDynamicOpsan encoder accepts. -
of
static <T,R> TypedEncoder<T,R> of(Class<R> resultClass, Function<? super T, ? extends R> encoder, Function<? super R, ? extends T> decoder) Creates a newTypedEncodergiven two functions to encode and decode an object. If a functions throws an exception, it is wrapped into an erroredDataResult.
-