Interface BabelNetworkSerializer<T extends @Nullable Object>

Type Parameters:
T - the type of object this serializer handles
All Known Subinterfaces:
BabelNetworkMessageSerializer<T>, BabelNodeComponentSerializer<T>, BabelNodeSerializer<T>
All Known Implementing Classes:
ArraySerializer, AsciiStringSerializer, BabelMessageSerializer, BasicSignedBabelMessageSerializer, BooleanArraySerializer, BooleanSerializer, ByteArraySerializer, ByteSerializer, ChannelInfoSerializer, CharacterSerializer, CharSequenceSerializer, DoubleArraySerializer, DoubleSerializer, FloatArraySerializer, FloatSerializer, FullSignedBabelMessageSerializer, GeneralBabelNodeComponentSerializer, GeneralBabelNodeSerializer, InetSocketAddressSerializer, IntArraySerializer, IntegerSerializer, IPBabelNodeComponentSerialiazer, ListSerializer, LongArraySerializer, LongSerializer, MapSerializer, PublicKeyBabelNodeSerializer, SetSerializer, ShortArraySerializer, ShortSerializer, SortedMapSerializer, SortedSetSerializer, StringSerializer, UUIDSerializer

public interface BabelNetworkSerializer<T extends @Nullable Object>
Low-level binary serializer contract for objects that need to be written to or read from a Netty ByteBuf.

Implementations are discovered at runtime through the Java ServiceLoader mechanism (annotate concrete classes with AutoService(BabelNetworkSerializer.class)). The SerializerRegistry collects all discovered implementations and makes them available for lookup by object class.

Serializers for complete Babel messages should instead implement the more specific BabelNetworkMessageSerializer sub-interface, which additionally exposes a numeric message identifier used in the wire protocol.

  • Method Summary

    Modifier and Type
    Method
    Description
    deserialize(io.netty.buffer.ByteBuf in, NodeStore store)
    Reads an instance of T from the supplied buffer.
    default int
    Returns an estimated size in bytes for the given object.
    default int
    getEstimateSize(T object, @Nullable NodeStore store)
    Returns a size estimate to fit the entire object in a ByteBuf without needing resizes.
    Returns the class of objects handled by this serializer, used for registry lookup.
    void
    serialize(T object, io.netty.buffer.ByteBuf out, NodeStore store)
    Encodes object and appends the resulting bytes to out.
  • Method Details

    • deserialize

      T deserialize(io.netty.buffer.ByteBuf in, NodeStore store)
      Reads an instance of T from the supplied buffer. The buffer's reader index must be positioned at the first byte of the encoded object. Upon return the reader index is advanced past all bytes consumed.
      Parameters:
      in - the source buffer
      store - the node store context for resolving node components
      Returns:
      the deserialized object
    • serialize

      void serialize(T object, io.netty.buffer.ByteBuf out, NodeStore store)
      Encodes object and appends the resulting bytes to out.
      Parameters:
      object - the object to serialize
      out - the destination buffer
      store - the node store context for resolving node components
    • getObjectClass

      Class<T> getObjectClass()
      Returns the class of objects handled by this serializer, used for registry lookup.
      Returns:
      the handled class
    • getEstimateSize

      default int getEstimateSize(T object)
      Returns an estimated size in bytes for the given object.
      Parameters:
      object - the object to estimate
      Returns:
      estimated byte size, or 0 if unknown
    • getEstimateSize

      default int getEstimateSize(T object, @Nullable NodeStore store)
      Returns a size estimate to fit the entire object in a ByteBuf without needing resizes. The default implementation returns 0. For maximum serialization performance, override this method.
      Parameters:
      object - the object to estimate the size
      store - the node store for node lookups during size estimation, or null
      Returns:
      the expected size in bytes to fit the object in a ByteBuf