Package com.mojang.serialization
Class MapCodec.MapCodecCodec<A>
java.lang.Object
com.mojang.serialization.MapCodec.MapCodecCodec<A>
- Type Parameters:
A
- the type to encode and decode
A
Codec
that encodes and decodes a MapCodec
.
These codecs are occasionally treated specially by other codec constructions - notably,
KeyDispatchCodec
will delegate to a MapCodec.MapCodecCodec
differently than
Additionally, this codec returns a remainder when decoding instead of consuming the entire input - this means that
the codec can be used more easily alongside Codec.pair(Codec, Codec)
than a "normal" codec, where the first
codec would consume the entire input.
Note: when further modifying a MapCodec.MapCodecCodec
, if you wish the "map-ness" of the codec to
be maintained (which you may to retain special behaviour with KeyDispatchCodec
or the like) you will want to use Codec.mapPair(MapCodec, MapCodec)
, MapCodec.flatXmap(Function, Function)
, and company.
in place of Codec.pair(Codec, Codec)
, Codec.flatXmap(Function, Function)
(Function, Function)}, and company.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.mojang.serialization.Codec
Codec.ResultFunction<A>
Nested classes/interfaces inherited from interface com.mojang.serialization.Decoder
Decoder.Boxed<A>, Decoder.Simple<A>, Decoder.Terminal<A>
-
Field Summary
Fields inherited from interface com.mojang.serialization.Codec
BOOL, BYTE, BYTE_BUFFER, DOUBLE, EMPTY, FLOAT, INT, INT_STREAM, LONG, LONG_STREAM, PASSTHROUGH, SHORT, STRING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncodec()
<T> DataResult<Pair<A,
T>> decode
(DynamicOps<T> ops, T input) Decodes an object from a serialized form, returning any remaining serialized data.<T> DataResult<T>
encode
(A input, DynamicOps<T> ops, T prefix) Encodes an object to a serialized form, adding to an existing prefix.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.mojang.serialization.Codec
comapFlatMap, deprecated, dispatch, dispatch, dispatchMap, dispatchMap, dispatchStable, fieldOf, flatComapMap, flatXmap, listOf, mapResult, optionalFieldOf, optionalFieldOf, optionalFieldOf, optionalFieldOf, orElse, orElse, orElse, orElseGet, orElseGet, orElseGet, partialDispatch, promotePartial, stable, withLifecycle, xmap
Methods inherited from interface com.mojang.serialization.Decoder
boxed, decode, flatMap, map, parse, parse, simple, terminal
Methods inherited from interface com.mojang.serialization.Encoder
comap, encodeStart, flatComap
-
Constructor Details
-
MapCodecCodec
-
-
Method Details
-
codec
-
decode
Description copied from interface:Decoder
Decodes an object from a serialized form, returning any remaining serialized data.- Specified by:
decode
in interfaceDecoder<A>
- 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
-
encode
Description copied from interface:Encoder
Encodes an object to a serialized form, adding to an existing prefix.- Specified by:
encode
in interfaceEncoder<A>
- Type Parameters:
T
- the type to serialize to- Parameters:
input
- the object to encodeops
- aDynamicOps
for the target serialized formatprefix
- existing data that the encoded object should be added to- Returns:
- a
DataResult
containing the serialized form of the object, or an error if the object could not be serialized
-
toString
-