Class TransformingType<F,T>

java.lang.Object
com.viaversion.viaversion.api.type.Type<T>
com.viaversion.viaversion.api.type.TransformingType<F,T>
All Implemented Interfaces:
ByteBufReader<T>, ByteBufWriter<T>, CodecWriter<T>

public class TransformingType<F,T> extends Type<T>
  • Constructor Details

  • Method Details

    • of

      public static <F, T> Type<T> of(Type<F> from, Class<T> outputClass, Function<F,T> mapFunction, Function<T,F> reverseFunction)
      Returns a type that transforms the input to a separate output type. Useful if you have wrapper classes of a single object.
      Type Parameters:
      F - from type
      T - to type
      Parameters:
      from - type to map from
      outputClass - output class
      mapFunction - function to map from F to T
      reverseFunction - function to map from T to F
      Returns:
      transforming type
    • read

      public T read(io.netty.buffer.ByteBuf buffer)
      Description copied from interface: ByteBufReader
      Reads a value from a ByteBuf.
      Parameters:
      buffer - buffer to read from
      Returns:
      type based on the class type
    • write

      public void write(io.netty.buffer.ByteBuf buffer, T value)
      Description copied from interface: ByteBufWriter
      Writes an object to a type to a ByteBuf.
      Parameters:
      buffer - buffer to write to
      value - value to write
    • write

      public void write(Ops ops, T value)
      Specified by:
      write in interface CodecWriter<F>
      Overrides:
      write in class Type<T>