berconpy.protocol.ClientPacket¶
- class berconpy.protocol.ClientPacket(data)¶
Bases:
PacketThe base class for packets sent by the client.
The subclasses of this packet are:
Methods
assert_checksum(checksum)Asserts that the packet has a given checksum.
from_bytes(cls, data, *, from_client)Constructs a packet from the given data.
Attributes
dataThe CRC32 checksum included in the header.
The zero-based index of the packet associated with a COMMAND server response.
A boolean indicating if the server authenticated the client.
The message that was sent to the client/server.
The sequence number of the COMMAND or MESSAGE packet.
The total number of packets associated with a COMMAND server response.
The packet's type defined in the protocol.
- assert_checksum(checksum)¶
Asserts that the packet has a given checksum.
- Returns:
The same packet object, helpful for method chaining.
- Raises:
ValueError – The checksum was incorrect.
- classmethod from_bytes(cls, data, *, from_client)¶
Constructs a packet from the given data.
- Parameters:
- Return type:
- Returns:
The corresponding subclass of Packet.
- Raises:
ValueError – The given data is malformed and does not match the packet specification.
- property index: int | None¶
The zero-based index of the packet associated with a COMMAND server response.
If a sub-header is not provided with the response, this defaults to 0.
- property message: bytes | None¶
The message that was sent to the client/server.
While returned as bytes, this should be decodable as a UTF-8 string, with the exception of
ServerMessagePacketobjects which only need to be decodable when all of the messages are joined together.For LOGIN, this would be the password sent to the server. For COMMAND, this would be the command string sent to the server. For MESSAGE, this would be the message sent to the client.
- property total: int | None¶
The total number of packets associated with a COMMAND server response.
If a sub-header is not provided with the response, this defaults to 1.
- property type: PacketType¶
The packet’s type defined in the protocol.
This property is computed from the
dataattribute of the packet which in typical cases should correspond with the type of the class itself.See also