Class SerializerMessageProtocol

java.lang.Object
com.jme3.network.base.protocol.SerializerMessageProtocol
All Implemented Interfaces:
MessageProtocol

public class SerializerMessageProtocol extends Object implements MessageProtocol
Implements a MessageProtocol providing message serializer/deserialization based on the built-in Serializer code.

The protocol is based on a simple length + data format where two bytes represent the (short) length of the data and the rest is the raw data for the Serializers class.

Author:
Paul Speed
  • Field Details

  • Constructor Details

    • SerializerMessageProtocol

      public SerializerMessageProtocol()
      Creates a serializer-backed message protocol.
  • Method Details

    • toByteBuffer

      public ByteBuffer toByteBuffer(Message message, ByteBuffer target)
      Converts a message to a ByteBuffer using the com.jme3.network.serializing.Serializer and the (short length) + data protocol. If target is null then a 32k byte buffer will be created and filled.
      Specified by:
      toByteBuffer in interface MessageProtocol
      Parameters:
      message - the message to serialize
      target - the optional target buffer to reuse
      Returns:
      a buffer containing the serialized message
    • toMessage

      public Message toMessage(ByteBuffer bytes)
      Creates and returns a message from the properly sized byte buffer using com.jme3.network.serializing.Serializer.
      Specified by:
      toMessage in interface MessageProtocol
      Parameters:
      bytes - the serialized message bytes
      Returns:
      the decoded message
    • createBuffer

      public MessageBuffer createBuffer()
      Description copied from interface: MessageProtocol
      Creates a rolling message buffer compatible with this protocol.
      Specified by:
      createBuffer in interface MessageProtocol
      Returns:
      a new message buffer