Class BasicSignedBabelMessageSerializer<T extends BabelMessage>
java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.BasicSignedBabelMessageSerializer<T>
- Type Parameters:
T- the type of the innerBabelMessage
- All Implemented Interfaces:
BabelNetworkMessageSerializer<SignedBabelMessage<T>>, BabelNetworkSerializer<SignedBabelMessage<T>>
- Direct Known Subclasses:
FullSignedBabelMessageSerializer
public class BasicSignedBabelMessageSerializer<T extends BabelMessage>
extends Object
implements BabelNetworkMessageSerializer<SignedBabelMessage<T>>
Serializer and verifier for
SignedBabelMessage instances wrapping a message of type T.
During deserialization, this serializer reads a 4-byte length prefix, extracts a slice containing the
inner message bytes, deserializes the sender BabelNode (which must implement
PublicKeyBabelNode), verifies the signature using the sender's public key,
and deserializes the inner message payload using innerSerializer.
During serialization, this basic serializer can relay or forward already-signed messages (possessing
both a sender and a signature). Attempting to serialize an unsigned message throws UnsupportedOperationException;
use FullSignedBabelMessageSerializer when signing outgoing messages with a local private key.
-
Constructor Summary
ConstructorsConstructorDescriptionBasicSignedBabelMessageSerializer(BabelNetworkMessageSerializer<T> innerSerializer) Constructs a basic signed message serializer with the specified inner serializer. -
Method Summary
Modifier and TypeMethodDescriptiondeserialize(io.netty.buffer.ByteBuf in, NodeStore store) Reads an instance ofTfrom the supplied buffer.intgetEstimateSize(SignedBabelMessage<T> object) Returns an estimated size in bytes for the given object.intgetId()Returns the unique numeric identifier for the message type handled by this serializer.protected BabelNetworkMessageSerializer<T> Returns the delegate serializer responsible for the inner message.Returns the class of objects handled by this serializer, used for registry lookup.voidserialize(SignedBabelMessage<T> object, io.netty.buffer.ByteBuf out, NodeStore store) Encodesobjectand appends the resulting bytes toout.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BabelNetworkSerializer
getEstimateSizeModifier and TypeMethodDescriptiondefault intgetEstimateSize(SignedBabelMessage<T> object, @Nullable NodeStore store) Returns a size estimate to fit the entire object in aByteBufwithout needing resizes.
-
Constructor Details
-
BasicSignedBabelMessageSerializer
Constructs a basic signed message serializer with the specified inner serializer.- Parameters:
innerSerializer- the delegate serializer for the inner message
-
-
Method Details
-
deserialize
Description copied from interface:BabelNetworkSerializerReads 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.- Specified by:
deserializein interfaceBabelNetworkSerializer<T extends BabelMessage>- Parameters:
in- the source bufferstore- the node store context for resolving node components- Returns:
- the deserialized object
-
serialize
Description copied from interface:BabelNetworkSerializerEncodesobjectand appends the resulting bytes toout.- Specified by:
serializein interfaceBabelNetworkSerializer<T extends BabelMessage>- Parameters:
object- the object to serializeout- the destination bufferstore- the node store context for resolving node components
-
getObjectClass
Description copied from interface:BabelNetworkSerializerReturns the class of objects handled by this serializer, used for registry lookup.- Specified by:
getObjectClassin interfaceBabelNetworkSerializer<T extends BabelMessage>- Returns:
- the handled class
-
getId
public int getId()Description copied from interface:BabelNetworkMessageSerializerReturns the unique numeric identifier for the message type handled by this serializer. The value corresponds to theidattribute of theBabelIPMessageannotation.- Specified by:
getIdin interfaceBabelNetworkMessageSerializer<T extends BabelMessage>- Returns:
- the message type identifier
-
getEstimateSize
Description copied from interface:BabelNetworkSerializerReturns an estimated size in bytes for the given object.- Specified by:
getEstimateSizein interfaceBabelNetworkSerializer<T extends BabelMessage>- Parameters:
object- the object to estimate- Returns:
- estimated byte size, or 0 if unknown
-
getInnerSerializer
Returns the delegate serializer responsible for the inner message.- Returns:
- the inner message serializer
-