Table of Contents

Class MessageSerializer

Namespace
SteamNetworkLib.Utilities
Assembly
SteamNetworkLib.dll

Utility methods for message serialization and deserialization.

public static class MessageSerializer
Inheritance
MessageSerializer
Inherited Members

Fields

MESSAGE_HEADER

Header identifier for SteamNetworkLib messages to validate message authenticity.

public const string MESSAGE_HEADER = "SNLM"

Field Value

string

Methods

CreateMessage<T>(byte[])

Creates a P2P message instance from serialized data.

public static T CreateMessage<T>(byte[] data) where T : P2PMessage, new()

Parameters

data byte[]

The serialized data.

Returns

T

Deserialized message instance.

Type Parameters

T

The message type to create.

Exceptions

P2PException

Thrown when creation fails or type mismatch occurs.

DeserializeMessage(byte[])

Deserializes a byte array to extract message type and data.

public static (string MessageType, byte[] MessageData) DeserializeMessage(byte[] data)

Parameters

data byte[]

The serialized data.

Returns

(string MessageType, byte[] MessageData)

Tuple containing message type and message data.

Exceptions

P2PException

Thrown when deserialization fails or data is invalid.

GetMessageType(byte[])

Gets the message type from serialized data without full deserialization.

public static string? GetMessageType(byte[] data)

Parameters

data byte[]

The serialized data.

Returns

string

Message type string, or null if invalid.

IsValidMessage(byte[])

Validates that data contains a valid SteamNetworkLib message.

public static bool IsValidMessage(byte[] data)

Parameters

data byte[]

The data to validate.

Returns

bool

True if the data contains a valid message.

SerializeMessage(P2PMessage)

Serializes a P2P message to a byte array with header validation.

public static byte[] SerializeMessage(P2PMessage message)

Parameters

message P2PMessage

The message to serialize.

Returns

byte[]

Serialized message data.

Exceptions

P2PException

Thrown when serialization fails.