Package org.kendar.sync.lib.protocol
Class Packet
java.lang.Object
org.kendar.sync.lib.protocol.Packet
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Packetdeserialize(byte[] data) Deserializes a packet from a byte array.intbyte[]byte[]Decompresses the content using ZLIB.intintbyte[]Serializes the packet to a byte array.
-
Constructor Details
-
Packet
public Packet() -
Packet
Creates a new packet with the specified parameters.- Parameters:
connectionId- The connection IDsessionId- The session IDpacketId- The packet IDmessageType- The message type (2 characters)content- The content of the packet (will be compressed)
-
-
Method Details
-
deserialize
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
-
getPacketId
public int getPacketId() -
getMessageType
-
getContent
public byte[] getContent()
-