Class VersionedCodec<T>

java.lang.Object
fr.robie.machineengine.api.data.VersionedCodec<T>
All Implemented Interfaces:
net.kyori.adventure.key.Keyed

public final class VersionedCodec<T> extends Object implements net.kyori.adventure.key.Keyed
A registered, versioned codec (ARCHITECTURE.md ยง20.3). Encoded data is wrapped as {v: <version>, data: <payload>}; decoding runs the migrations from the stored version up to version() first.

Data newer than version() is never decoded (no downgrades); callers keep it opaque.

  • Field Details

  • Method Details

    • builder

      @NotNull public static <T> @NotNull VersionedCodec.Builder<T> builder(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull StorageCodec<T> codec)
    • key

      @NotNull public @NotNull net.kyori.adventure.key.Key key()
      Specified by:
      key in interface net.kyori.adventure.key.Keyed
    • version

      public int version()
      Current data version, starting at 1.
    • codec

      @NotNull public @NotNull StorageCodec<T> codec()
    • migrations

      @NotNull public @NotNull List<DataMigration> migrations()
    • oldestSupportedVersion

      public int oldestSupportedVersion()
      Oldest data version that can still be decoded.
    • encode

      @NotNull public @NotNull DataMap encode(@NotNull T value)
    • decode

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

      @NotNull public @NotNull List<String> definitionProblems()
      Returns:
      problems with this codec's definition; empty if it is valid
    • toString

      public String toString()
      Overrides:
      toString in class Object