network.decode
Opens a packet for inspection.
Syntax
Signature
network.decode(Payload: Packet | table | string | buffer) -> PacketAliases
raknet.decodepackets.decodeRakNet.decode
Parameters
| Parameter | Type | Description |
|---|---|---|
Payload | Packet | table | string | buffer | Payload accepted by network.encode. |
Returns
| Type | Description |
|---|---|
Packet | Packet 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