Package anbxj

Interface Channel_MessageSerializer

All Known Implementing Classes:
Channel_JavaFramedSerializer, Channel_ProtobufSerializer

public interface Channel_MessageSerializer
A protocol-specific serializer that converts logical protocol-level objects to/from byte arrays. Implementations are generated by the AnBx compiler for each protocol and are typically backed by Protocol Buffers.

Each protocol step that involves a Send or Receive is assigned a unique step number. The serializer uses this number to select the correct message schema, enabling strongly-typed, self-describing wire formats that can be consumed by hand-written code in other languages (e.g., C++).

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    deserialize(byte[] data, int step)
    Deserializes a byte array back into a logical protocol message object.
    byte[]
    serialize(Object message, int step)
    Serializes a logical protocol message into a byte array.
    default void
    Injects the current AnB_Session into this serializer.
  • Method Details

    • serialize

      byte[] serialize(Object message, int step) throws IOException
      Serializes a logical protocol message into a byte array.
      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:
      IOException - if serialization fails
    • deserialize

      Object deserialize(byte[] data, int step) throws IOException, ClassNotFoundException
      Deserializes a byte array back into a logical protocol message object.
      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:
      IOException - if deserialization fails
      ClassNotFoundException - if a required class cannot be found (may occur when internal Java serialization is used inside cryptographic wrappers)
    • setSession

      default void setSession(AnB_Session session)
      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.

      Parameters:
      session - the current session (must not be null)