network.decode

Opens a packet for inspection.

Syntax

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

Aliases

  • raknet.decode
  • packets.decode
  • RakNet.decode

Parameters

ParameterTypeDescription
PayloadPacket | table | string | bufferPayload accepted by network.encode.

Returns

TypeDescription
PacketPacket object with raw bytes and lazily decoded fields.

Notes

Raw data is kept in data, and id and type are supplied when the packet tag is recognized. Accessing decoded parses the fields lazily. A decoding failure leaves decoded nil and sets decodeError. AsString, AsBuffer, and AsArray return raw representations. PacketId and Size are readonly convenience properties.

Example

Luau
local Packet = network.create("Chat", {
    sender_id = "0",
    username = "Example",
    text = "Hello",
})

local Decoded = network.decode(network.encode(Packet))
local Fields = Decoded.decoded
if Fields then
    print(Decoded.type, Fields.username, Fields.text)
else
    warn(Decoded.decodeError)
end