Class SortedSetSerializer<T extends Comparable<?>>

java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.serializers.collections.SortedSetSerializer<T>
Type Parameters:
T - the type of comparable elements in the set
All Implemented Interfaces:
BabelNetworkSerializer<SortedSet<T>>

public class SortedSetSerializer<T extends Comparable<?>> extends Object implements BabelNetworkSerializer<SortedSet<T>>
Network serializer for Java SortedSet collections.

Sorted sets are serialized by writing an integer size followed by each serialized element. Upon deserialization, an ImmutableSortedSet with natural ordering is constructed.

  • Constructor Details

    • SortedSetSerializer

      public SortedSetSerializer(BabelNetworkSerializer<T> serializer)
      Constructs a new sorted set serializer using the given element serializer.
      Parameters:
      serializer - the serializer for set elements
  • Method Details

    • serialize

      public void serialize(SortedSet<T> object, io.netty.buffer.ByteBuf out, NodeStore store)
      Description copied from interface: BabelNetworkSerializer
      Encodes object and appends the resulting bytes to out.
      Specified by:
      serialize in interface BabelNetworkSerializer<T extends Comparable<?>>
      Parameters:
      object - the object to serialize
      out - the destination buffer
      store - the node store context for resolving node components
    • deserialize

      public SortedSet<T> deserialize(io.netty.buffer.ByteBuf in, NodeStore store)
      Description copied from interface: BabelNetworkSerializer
      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.
      Specified by:
      deserialize in interface BabelNetworkSerializer<T extends Comparable<?>>
      Parameters:
      in - the source buffer
      store - the node store context for resolving node components
      Returns:
      the deserialized object
    • getObjectClass

      public Class<SortedSet<T>> getObjectClass()
      Description copied from interface: BabelNetworkSerializer
      Returns the class of objects handled by this serializer, used for registry lookup.
      Specified by:
      getObjectClass in interface BabelNetworkSerializer<T extends Comparable<?>>
      Returns:
      the handled class
    • getEstimateSize

      public int getEstimateSize(SortedSet<T> object)
      Description copied from interface: BabelNetworkSerializer
      Returns an estimated size in bytes for the given object.
      Specified by:
      getEstimateSize in interface BabelNetworkSerializer<T extends Comparable<?>>
      Parameters:
      object - the object to estimate
      Returns:
      estimated byte size, or 0 if unknown