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 TypeMethodDescriptiondeserialize(io.netty.buffer.ByteBuf in, NodeStore store) Reads an instance ofTfrom the supplied buffer.default intgetEstimateSize(T object) Returns an estimated size in bytes for the given object.default intgetEstimateSize(T object, @Nullable NodeStore store) Returns a size estimate to fit the entire object in aByteBufwithout needing resizes.Returns the class of objects handled by this serializer, used for registry lookup.voidEncodesobjectand appends the resulting bytes toout.
-
Method Details
-
deserialize
Reads an instance ofTfrom 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 bufferstore- the node store context for resolving node components- Returns:
- the deserialized object
-
serialize
-
getObjectClass
-
getEstimateSize
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
Returns a size estimate to fit the entire object in aByteBufwithout needing resizes. The default implementation returns 0. For maximum serialization performance, override this method.- Parameters:
object- the object to estimate the sizestore- the node store for node lookups during size estimation, ornull- Returns:
- the expected size in bytes to fit the object in a
ByteBuf
-