network.encode
Encodes a packet as wire bytes.
Syntax
Signature
network.encode(Payload: Packet | table | string | buffer) -> stringAliases
raknet.encodepackets.encodeRakNet.encode
Parameters
| Parameter | Type | Description |
|---|---|---|
Payload | Packet | table | string | buffer | Packet, decoded packet table, raw bytes, buffer, or dense byte array. |
Returns
| Type | Description |
|---|---|
string | Binary wire payload. |
Notes
Raw payloads may be strings, buffers, or dense arrays of byte values. Payloads must contain 1 through 65,535 bytes. Changed decoded fields are encoded using the packet's ID.
Example
Luau
local Packet = network.create("Chat", {
sender_id = "0",
username = "Example",
text = "Hello",
})
local Bytes = network.encode(Packet)
local Restored = network.decode(Bytes)
assert(Restored.decoded.text == "Hello")
print("Encoded bytes:", #Bytes)