Class ConnectionPayloadCodec
- Namespace
- Unity.Multiplayer.Core
The versioned binary form of a ConnectionPayload, carried in the transport's connection data.
public static class ConnectionPayloadCodec
- Inheritance
-
ConnectionPayloadCodec
- Inherited Members
Remarks
Format version 2, all integers little-endian, every string a one-byte length then that many UTF-8 bytes:
offset 0 2 bytes magic 'M' 'A' (0x4D 0x41)
2 1 byte format version (2)
3 string game version
8 bytes protocol hash (ulong)
string player token
string display name
4 bytes colour R, G, B, A
string server password (empty for none)
Format version 1 is the same without the password; it still decodes, as a payload with no password.
Rule for every future format version: the magic, the version byte and the game-version string keep their place and encoding. A server can then tell an out-of-date client "wrong game version" even when it cannot read the rest of the payload. Decoding is strict: missing or extra bytes fail.
Fields
CurrentFormatVersion
The format version Encode(ConnectionPayload) writes.
public const byte CurrentFormatVersion = 2
Field Value
Magic0
The first magic byte, 'M'.
public const byte Magic0 = 77
Field Value
Magic1
The second magic byte, 'A'.
public const byte Magic1 = 65
Field Value
MaxEncodedLength
Largest payload TryDecode(byte[]) looks at; anything longer is rejected unread.
public const int MaxEncodedLength = 1024
Field Value
OldestFormatVersion
The oldest format version TryDecode(byte[]) reads (it has no password field).
public const byte OldestFormatVersion = 1
Field Value
Methods
Encode(ConnectionPayload)
Encodes a valid payload in the current format.
public static byte[] Encode(ConnectionPayload payload)
Parameters
payloadConnectionPayload
Returns
- byte[]
Exceptions
- ArgumentNullException
payloadis null.- ArgumentException
The payload fails Validate().
TryDecode(byte[])
Decodes connection data. Never throws on bad input: every failure comes back as a PayloadDecodeResult with a PayloadDecodeError and a message.
public static PayloadDecodeResult TryDecode(byte[] data)
Parameters
databyte[]