blob: b1e72edc6f0aab7fa7b7f8b7231bbcadc3828e72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
class_name Packet
# set to 0 if variable length
#const BYTE_LENGTH := 0
var byte_length: int = 0:
get = get_byte_length
## Override if packet has variable length.
func get_byte_length() -> int:
return self.BYTE_LENGTH
## Get header to prepend to the packet. [br]
## [param packet_length] is only needed when the packet has a variable length.
func get_header(packet_length: int = 0) -> PackedByteArray:
var bytes = PackedByteArray([0,0])
bytes.encode_u16(0, self.HEADER)
if packet_length > 0:
bytes.resize(4)
bytes.encode_u16(2, packet_length)
return bytes
|