network.encode

Encodes a packet as wire bytes.

Syntax

Signature
network.encode(Payload: Packet | table | string | buffer) -> string

Aliases

  • raknet.encode
  • packets.encode
  • RakNet.encode

Parameters

ParameterTypeDescription
PayloadPacket | table | string | bufferPacket, decoded packet table, raw bytes, buffer, or dense byte array.

Returns

TypeDescription
stringBinary 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)