Interface Serializer<T>

Type Parameters:
T - the target type of this serializer.
All Known Implementing Classes:
Serializer.Provided, UUIDSerializer

public interface Serializer<T>
Writes/reads an object to/from a binary stream.
Author:
Paul Ferraro
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Serializer<T>
    of(T value)
     
    read(DataInput input)
    Reads an object from the specified input stream.
    default OptionalInt
    size(T object)
    Returns the size of the buffer to use for marshalling the specified object, if known.
    default Formatter<T>
    toFormatter(Class<? extends T> type)
    Creates a Formatter based on this serializer.
    default <V> Serializer<V>
    wrap(Function<V,T> unwrapper, Function<T,V> wrapper)
    Creates a wrapped serializer that delegates to this serializer applying the specified wrapping/unwrapping functions.
    void
    write(DataOutput output, T value)
    Writes the specified object to the specified output stream
  • Method Details

    • write

      void write(DataOutput output, T value) throws IOException
      Writes the specified object to the specified output stream
      Parameters:
      output - the data output stream
      value - an object to serialize
      Throws:
      IOException - if an I/O error occurs
    • read

      T read(DataInput input) throws IOException
      Reads an object from the specified input stream.
      Parameters:
      input - a data input stream
      Returns:
      the deserialized object
      Throws:
      IOException - if an I/O error occurs
    • size

      default OptionalInt size(T object)
      Returns the size of the buffer to use for marshalling the specified object, if known.
      Parameters:
      object - the object to be sized
      Returns:
      the buffer size (in bytes), or empty if unknown.
    • wrap

      default <V> Serializer<V> wrap(Function<V,T> unwrapper, Function<T,V> wrapper)
      Creates a wrapped serializer that delegates to this serializer applying the specified wrapping/unwrapping functions.
      Type Parameters:
      V - the wrapper type
      Parameters:
      unwrapper - an unwrapping function
      wrapper - a wrapping function
      Returns:
      a wrapped serializer
    • toFormatter

      default Formatter<T> toFormatter(Class<? extends T> type)
      Creates a Formatter based on this serializer.
      Parameters:
      type - the serialized type
      Returns:
      a new formatter
    • of

      static <T> Serializer<T> of(T value)