Package anbxj

Class Channel_ProtobufSerializer

java.lang.Object
anbxj.Channel_ProtobufSerializer
All Implemented Interfaces:
Channel_MessageSerializer

public final class Channel_ProtobufSerializer extends Object implements Channel_MessageSerializer
A Channel_MessageSerializer that uses step-specific descriptors to convert Java objects (e.g., AnBx_WireFormats.SignedMessage, AnBx_WireFormats.SealedMessage) into typed Protobuf messages and back.

This serializer is intended for the ProtoBuf serialization mode (typed Protobuf). For each protocol step, a Channel_ProtobufSerializer.StepDescriptor must be provided that knows the exact Protobuf message type for that step. The mapping from step number to its descriptor is injected at construction time.

The serialization process follows two directions:

See Also:
  • Constructor Details

  • Method Details

    • setSession

      public void setSession(AnB_Session session)
      Description copied from interface: Channel_MessageSerializer
      Injects the current AnB_Session into this serializer.

      The default implementation does nothing. Subclasses that require access to the session (e.g., for cryptographic operations during field extraction) should override this method and store the reference.

      Specified by:
      setSession in interface Channel_MessageSerializer
      Parameters:
      session - the current session (must not be null)
    • serialize

      public byte[] serialize(Object message, int step) throws IOException
      Serializes a logical protocol message into a byte array.
      Specified by:
      serialize in interface Channel_MessageSerializer
      Parameters:
      message - the object to send; the concrete type depends on the protocol step (e.g., String, Crypto_SealedPair, Object[] for tuples)
      step - the protocol step number (starting from 1), used to identify the message format
      Returns:
      the serialized bytes, ready to be written to the network
      Throws:
      IllegalArgumentException - if no descriptor is registered for step
      IOException - if serialization fails
    • deserialize

      public Object deserialize(byte[] data, int step) throws IOException, ClassNotFoundException
      Deserializes a byte array back into a logical protocol message object.
      Specified by:
      deserialize in interface Channel_MessageSerializer
      Parameters:
      data - the raw bytes received from the network
      step - the expected protocol step number, used to identify the message format and recreate the appropriate object
      Returns:
      the reconstructed protocol object (e.g., String, Crypto_SealedPair, Object[])
      Throws:
      IllegalArgumentException - if no descriptor is registered for step
      IOException - if deserialization fails
      ClassNotFoundException - if a required class cannot be found (may occur when internal Java serialization is used inside cryptographic wrappers)