Package com.mojang.serialization
Interface Decoder<A>
- Type Parameters:
A
- the type of object to decode
- All Known Subinterfaces:
Codec<A>
,PrimitiveCodec<A>
- All Known Implementing Classes:
CompoundListCodec
,EitherCodec
,ListCodec
,MapCodec.MapCodecCodec
,PairCodec
,UnboundedMapCodec
public interface Decoder<A>
Decodes objects from a serialized form.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Like aDecoder
, but deserializes from aDynamic
, which combines the serialized form and theDynamicOps
for that form.static interface
Like aDecoder.Terminal
, but deserializes from aDynamic
, which combines the serialized form and theDynamicOps
for that form.static interface
Can decode an object from a serialized form, but does not return any remaining serialized data. -
Method Summary
Modifier and TypeMethodDescriptiondefault Decoder.Boxed<A>
boxed()
Returns a boxed decoder that has the same behaviour as this decoder.default <T> DataResult<Pair<A,
T>> Decode an object from a serialized form, returning any remaining serialized data.<T> DataResult<Pair<A,
T>> decode
(DynamicOps<T> ops, T input) Decodes an object from a serialized form, returning any remaining serialized data.static <A> Decoder<A>
Returns a decoder which always errors.default MapDecoder<A>
Returns a map decoder that decodes a single field with the given name using this decoder.default <B> Decoder<B>
flatMap
(Function<? super A, ? extends DataResult<? extends B>> function) Transforms the type of this decoder using the given function, where the transformation may fail.default <B> Decoder<B>
Transforms the type of this decoder using the given function.static <A> Decoder<A>
ofBoxed
(Decoder.Boxed<? extends A> boxed) Returns a decoder which decodes from a combined serialized form and format.static <A> Decoder<A>
ofSimple
(Decoder.Simple<? extends A> simple) Returns a decoder which decodes from a combined serialized form and format,.static <A> Decoder<A>
ofTerminal
(Decoder.Terminal<? extends A> terminal) Returns a decoder which throws out any remaining serialized data.default <T> DataResult<A>
Parse a serialized form as an instance of this decoder's type.default <T> DataResult<A>
parse
(DynamicOps<T> ops, T input) promotePartial
(Consumer<String> onError) Returns a new decoder that decodes the same object as this decoder, but also runs the given action on an error.default Decoder.Simple<A>
simple()
Returns a simple decoder that has the same behaviour as this decoder, but discards any remaining serialized data.default Decoder.Terminal<A>
terminal()
Returns a terminal decoder that uses this decoder to decode an object from a serialized form, but does not return any remaining serialized data.static <A> MapDecoder<A>
unit
(A instance) Returns a decoder which always decodes the given object.static <A> MapDecoder<A>
Returns a decoder which always decodes an object taken from the given supplier.withLifecycle
(Lifecycle lifecycle) Returns a decoder which decodes the same object as this decoder, but attaches the given lifecycle to the result.
-
Method Details
-
decode
Decodes an object from a serialized form, returning any remaining serialized data.- Type Parameters:
T
- the type of the serialized form- Parameters:
ops
- aDynamicOps
for the serialized forminput
- the serialized form to decode- Returns:
- a
DataResult
containing the decoded object and any remaining serialized data, or an error if the object could not be decoded
-
parse
-
decode
Decode an object from a serialized form, returning any remaining serialized data.- Type Parameters:
T
- the type of the serialized form- Parameters:
input
- theDynamic
, containing serialized data, to decode- Returns:
- a
DataResult
containing the decoded object and any remaining serialized data, or an error if the object could not be decoded
-
parse
Parse a serialized form as an instance of this decoder's type.- Type Parameters:
T
- the type of the serialized form- Parameters:
input
- theDynamic
, containing serialized data, to parse- Returns:
- a
DataResult
containing the parsed object, or an error if the object could not be parsed
-
terminal
Returns a terminal decoder that uses this decoder to decode an object from a serialized form, but does not return any remaining serialized data.- Returns:
- a terminal decoder that uses this decoder to decode an object from a serialized form, but does not return any remaining serialized data
- See Also:
-
boxed
Returns a boxed decoder that has the same behaviour as this decoder.- Returns:
- a boxed decoder that has the same behaviour as this decoder
- See Also:
-
simple
Returns a simple decoder that has the same behaviour as this decoder, but discards any remaining serialized data.- Returns:
- a simple decoder that has the same behaviour as this decoder, but discards any remaining serialized data
- See Also:
-
fieldOf
Returns a map decoder that decodes a single field with the given name using this decoder.- Parameters:
name
- the name of the field to decode- Returns:
- a map decoder that decodes a single field with the given name using this decoder
- See Also:
-
flatMap
Transforms the type of this decoder using the given function, where the transformation may fail.- Type Parameters:
B
- the type of object for the new decoder to decode- Parameters:
function
- a function to apply to the decoded object- Returns:
- a new decoder
-
map
Transforms the type of this decoder using the given function.- Type Parameters:
B
- the type of object for the new decoder to decode- Parameters:
function
- a function to apply to the decoded object- Returns:
- a new decoder
-
promotePartial
Returns a new decoder that decodes the same object as this decoder, but also runs the given action on an error.- Parameters:
onError
- an action to run on an error- Returns:
- a new decoder that decodes the same object as this decoder, but also runs the given action on an error
-
withLifecycle
Returns a decoder which decodes the same object as this decoder, but attaches the given lifecycle to the result.- Parameters:
lifecycle
- theLifecycle
of the decoded object- Returns:
- a decoder which decodes the same object as this decoder, but attaches the given lifecycle to the result
-
ofTerminal
Returns a decoder which throws out any remaining serialized data.- Type Parameters:
A
- the type of object to decode- Parameters:
terminal
- aDecoder.Terminal
with the desired decoding logic- Returns:
- a decoder which throws out any remaining serialized data
-
ofBoxed
Returns a decoder which decodes from a combined serialized form and format.- Type Parameters:
A
- the type of object to decode- Parameters:
boxed
- aDecoder.Boxed
with the desired decoding logic- Returns:
- a decoder which decodes from a combined serialized form and format
-
ofSimple
Returns a decoder which decodes from a combined serialized form and format,.- Type Parameters:
A
- the type of object to decode- Parameters:
simple
- aDecoder.Simple
with the desired decoding logic- Returns:
- a decoder which decodes from a combined serialized form and format,
-
unit
Returns a decoder which always decodes the given object.- Type Parameters:
A
- the type of object to decode- Parameters:
instance
- the object to decode- Returns:
- a decoder which always decodes the given object
-
unit
Returns a decoder which always decodes an object taken from the given supplier.- Type Parameters:
A
- the type of object to decode- Parameters:
instance
- provides the object to decode- Returns:
- a decoder which always decodes an object taken from the given supplier
-
error
Returns a decoder which always errors.- Type Parameters:
A
- the type of object to (fail to) decode- Parameters:
error
- the error message to provide- Returns:
- a decoder which always errors
-