Interface Codec<T>
- Type Parameters:
T- the type of the data
- All Known Implementing Classes:
MapCodec
-
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NotNull Codec<T> byValueType(Type.Value<T> type) Gets theCodecof the specifiedType.Value.static <A> @NotNull Codec<A> static <A> @NotNull Codec<A> codec(@NotNull Encoder<? super A> encoder, @NotNull Decoder<? extends A> decoder, @NotNull String name) default <A> @NotNull Codec<A> flatXmap(@NotNull Function<? super A, dev.siroshun.jfun.result.Result<T, EncodeError>> fromA, @NotNull Function<? super T, dev.siroshun.jfun.result.Result<A, DecodeError>> toA) Maps the data from the providedCodecto another type and flattens theResult.default @NotNull Codec<Collection<T>> default @NotNull FieldCodecBuilder<T> toFieldCodec(@NotNull String fieldName) Creates a newFieldCodecBuilderforCodec.toMapCodecAsKey(@NotNull Codec<V> valueCodec) toMapCodecAsValue(@NotNull Codec<K> keyCodec) default <A> @NotNull Codec<A> Maps the data from the providedCodecto another type.Methods inherited from interface dev.siroshun.codec4j.api.decoder.Decoder
catchError, decode, flatMap, inspect, map, toListDecoder, toOptionalFieldDecoder, toRequiredFieldDecoder, toSetDecoder, toSetDecoder, toSupplyingFieldDecoderMethods inherited from interface dev.siroshun.codec4j.api.encoder.Encoder
comap, encode, flatComap, toCollectionEncoder, toFieldEncoder, toFieldEncoder
-
Field Details
-
BOOLEAN
ACodecforBoolean.This
CodeccallsOut.writeBoolean(boolean)for encoding, andIn.readAsBoolean()for decoding. -
BYTE
ACodecforByte.This
CodeccallsOut.writeByte(byte)for encoding, andIn.readAsByte()for decoding. -
CHAR
ACodecforCharacter.This
CodeccallsOut.writeByte(byte)for encoding, andIn.readAsChar()for decoding. -
DOUBLE
ACodecforDouble.This
CodeccallsOut.writeDouble(double)for encoding, andIn.readAsDouble()for decoding. -
FLOAT
ACodecforFloat.This
CodeccallsOut.writeFloat(float)for encoding, andIn.readAsFloat()for decoding. -
INT
ACodecforInteger.This
CodeccallsOut.writeInt(int)for encoding, andIn.readAsInt()for decoding. -
LONG
ACodecforLong.This
CodeccallsOut.writeLong(long)for encoding, andIn.readAsLong()for decoding. -
SHORT
ACodecforShort.This
CodeccallsOut.writeShort(short)for encoding, andIn.readAsShort()for decoding. -
STRING
ACodecforString.This
CodeccallsOut.writeString(String)for encoding, andIn.readAsString()for decoding.
-
-
Method Details
-
codec
-
codec
-
xmap
@NotNull default <A> @NotNull Codec<A> xmap(@NotNull @NotNull Function<? super A, ? extends T> fromA, @NotNull @NotNull Function<? super T, ? extends A> toA) Maps the data from the providedCodecto another type. -
flatXmap
@NotNull default <A> @NotNull Codec<A> flatXmap(@NotNull @NotNull Function<? super A, dev.siroshun.jfun.result.Result<T, EncodeError>> fromA, @NotNull @NotNull Function<? super T, dev.siroshun.jfun.result.Result<A, DecodeError>> toA) Maps the data from the providedCodecto another type and flattens theResult.- Type Parameters:
A- the type of the mapped data- Parameters:
fromA- theFunctionto map the data from the providedCodecto another type and returns aResultof the mappingtoA- theFunctionto map the data from another type to the providedCodecand returns aResultof the mapping- Returns:
- a new
Codecthat maps the data from the providedCodecto another type and flattens theResult
-
named
-
toListCodec
-
toSetCodec
-
toCollectionCodec
- Returns:
- a new
CodecforCollectionofCodec
-
toMapCodecAsKey
-
toMapCodecAsValue
-
toFieldCodec
Creates a newFieldCodecBuilderforCodec.- Parameters:
fieldName- the name of the field- Returns:
- a new
FieldCodecforCodec
-
byValueType
Gets theCodecof the specifiedType.Value.- Type Parameters:
T- the type of the value- Parameters:
type- theType.Valueto getCodec- Returns:
- the
Codecof the specifiedType.Value
-