Class Packet

java.lang.Object
org.kendar.sync.lib.protocol.Packet

public class Packet extends Object
Represents a packet in the sync protocol. Packet structure: - Integer: length of the packet including itself - Integer: The connection id (used to parallelize the communication. Starts from 0 for the connection) - UUID: The session id (defined in the connection phase, is unique for the whole session) - Integer: packet id used when sending data in multiple blocks - char[2]: containing the type of message - byte[]: containing the zipped content of the message
  • Constructor Details

    • Packet

      public Packet()
    • Packet

      public Packet(int connectionId, UUID sessionId, int packetId, String messageType, byte[] content)
      Creates a new packet with the specified parameters.
      Parameters:
      connectionId - The connection ID
      sessionId - The session ID
      packetId - The packet ID
      messageType - The message type (2 characters)
      content - The content of the packet (will be compressed)
  • Method Details

    • deserialize

      public static Packet deserialize(byte[] data)
      Deserializes a packet from a byte array.
      Parameters:
      data - The serialized packet
      Returns:
      The deserialized packet
    • serialize

      public byte[] serialize()
      Serializes the packet to a byte array.
      Returns:
      The serialized packet
    • getDecompressedContent

      public byte[] getDecompressedContent()
      Decompresses the content using ZLIB.
      Returns:
      The decompressed content
    • getLength

      public int getLength()
    • getConnectionId

      public int getConnectionId()
    • getSessionId

      public UUID getSessionId()
    • getPacketId

      public int getPacketId()
    • getMessageType

      public String getMessageType()
    • getContent

      public byte[] getContent()