Table of Contents

Class DataPacketSerializer

Namespace
BSGameLib.Networking
Assembly
BSGameLib.Networking.dll

Converts packets to and from the bytes of a frame.

public static class DataPacketSerializer
Inheritance
DataPacketSerializer
Inherited Members

Remarks

A frame is a 40-character type hash, a 4-byte big-endian payload length, then the payload. The payload holds the packet's public instance properties in declaration order.

Methods

Deserialize(Type, byte[])

Creates a packetType from data, which is the payload without the header. The constructor does not run. A payload that ends early, from a packet built before a property was added, leaves the later properties at their defaults.

public static IDataPacket Deserialize(Type packetType, byte[] data)

Parameters

packetType Type
data byte[]

Returns

IDataPacket

Deserialize<T>(byte[])

Creates a T from data, which is the payload without the header. The packet's constructor does not run.

public static T Deserialize<T>(byte[] data) where T : class, IDataPacket, new()

Parameters

data byte[]

Returns

T

Type Parameters

T

Serialize(IDataPacket)

Returns the frame for packet: its type hash, its payload length and its payload.

public static byte[] Serialize(IDataPacket packet)

Parameters

packet IDataPacket

Returns

byte[]

Exceptions

NotSupportedException

A property has a type that cannot be serialized.

Serialize<T>(T)

Returns the frame for packet. Same as Serialize(IDataPacket).

public static byte[] Serialize<T>(T packet) where T : class, IDataPacket

Parameters

packet T

Returns

byte[]

Type Parameters

T