Interface StorageCodec<T>


public interface StorageCodec<T>
Encodes values to DataValues and back. Decoding never throws for bad data; it returns an error Result (usually a MachineError.SerializationError).

Persisted data must go through a VersionedCodec so it can be migrated later.

  • Method Details

    • encode

      @NotNull @NotNull DataValue encode(@NotNull T value)
    • decode

      @NotNull @NotNull Result<T> decode(@NotNull @NotNull DataValue data)
    • of

      @NotNull static <T> @NotNull StorageCodec<T> of(@NotNull @NotNull Function<? super T, ? extends DataValue> encoder, @NotNull @NotNull Function<? super DataValue, Result<T>> decoder)
    • xmap

      @NotNull default <R> @NotNull StorageCodec<R> xmap(@NotNull @NotNull Function<? super T, ? extends R> to, @NotNull @NotNull Function<? super R, ? extends T> from)
      Maps this codec to another type with a total, two-way conversion.
    • flatXmap

      @NotNull default <R> @NotNull StorageCodec<R> flatXmap(@NotNull @NotNull Function<? super T, Result<R>> to, @NotNull @NotNull Function<? super R, ? extends T> from)
      Maps this codec to another type when decoding may fail.