Class FunctionalObjectSerializer<T>

java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.object.serializers.FunctionalObjectSerializer<T>
Type Parameters:
T - the type of data to write/read from the buffer.
All Implemented Interfaces:
ObjectSerializer<T>

public final class FunctionalObjectSerializer<T> extends Object implements ObjectSerializer<T>
An object serializer instance which passes the read and write calls to the functional providers previously added.
Since:
4.0
  • Field Details

  • Constructor Details

  • Method Details

    • of

      Constructs a new functional object serializer instance.
      Parameters:
      reader - the reader to read the content from the buffer.
      writer - the writer which writes the given data to the buffer.
      Returns:
      the created functional object serializer instance.
      Throws:
      NullPointerException - if either the writer or reader is null.
    • read

      Reads the object from the buffer. This method should only read the content from the buffer which was written to it previously, never more as the given buffer is not a slice of the buffer representing the object being read. Although this method returns an object, the returned object must always match the given type during object construction. The object return type is just a helper, but the return value will be cast to the given type resulting in errors if provided with the wrong type of object.
      Specified by:
      read in interface ObjectSerializer<T>
      Parameters:
      source - the buffer to read the object from.
      type - the type of the object to read.
      caller - the mapper to which this serializer is registered and from which the deserialize request call came.
      Returns:
      the deserialized object of the serializer type T, or null if not readable.
    • write

      public void write(@NonNull DataBuf.Mutable dataBuf, @Nullable T object, @NonNull @NonNull Type type, @NonNull @NonNull ObjectMapper caller)
      Writes the given object into the given buffer for network transfer and later deserialization.
      Specified by:
      write in interface ObjectSerializer<T>
      Parameters:
      dataBuf - the buffer to write the data to.
      object - the object to serialize.
      type - the raw type of the object.
      caller - the object mapper to which this serializer belongs and which requested the serialisation.