diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-28 18:38:42 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-28 18:38:42 +0100 |
commit | e8aa9f50886b66d525307a58d71036e6fd3d4aa1 (patch) | |
tree | ce6f59eecf1eb3e1ba2794166c09623d8a2d7d83 /packets/packet.gd | |
parent | c89f25f59aa493d95bcac8e75ca5cdd57a0403e7 (diff) |
next commit
Diffstat (limited to 'packets/packet.gd')
-rw-r--r-- | packets/packet.gd | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packets/packet.gd b/packets/packet.gd index ea1621c..9f82782 100644 --- a/packets/packet.gd +++ b/packets/packet.gd @@ -1 +1,24 @@ class_name Packet + + +#static var header: int = 0 + +var byte_length: int = 0 + + +## Override if packet has variable length +func get_byte_length() -> int: + return 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 |