Show / Hide Table of Contents

Class NetSerializer

Inheritance
object
NetSerializer
Namespace: LiteNetLib.Utils
Assembly: LiteNetLib.dll
Syntax
public class NetSerializer

Constructors

NetSerializer()

Declaration
public NetSerializer()

NetSerializer(int)

Declaration
public NetSerializer(int maxStringLength)
Parameters
Type Name Description
int maxStringLength

Methods

Deserialize<T>(NetDataReader)

Reads packet with known type

Declaration
public T Deserialize<T>(NetDataReader reader) where T : class, new()
Parameters
Type Name Description
NetDataReader reader

NetDataReader with packet

Returns
Type Description
T

Returns packet if packet in reader is matched type

Type Parameters
Name Description
T
Exceptions
Type Condition
InvalidTypeException

T's fields are not supported, or it has no fields

Deserialize<T>(NetDataReader, T)

Reads packet with known type (non alloc variant)

Declaration
public bool Deserialize<T>(NetDataReader reader, T target) where T : class, new()
Parameters
Type Name Description
NetDataReader reader

NetDataReader with packet

T target

Deserialization target

Returns
Type Description
bool

Returns true if packet in reader is matched type

Type Parameters
Name Description
T
Exceptions
Type Condition
InvalidTypeException

T's fields are not supported, or it has no fields

RegisterNestedType<T>()

Register custom property type

Declaration
public void RegisterNestedType<T>() where T : struct, INetSerializable
Type Parameters
Name Description
T

INetSerializable structure

RegisterNestedType<T>(Action<NetDataWriter, T>, Func<NetDataReader, T>)

Register custom property type

Declaration
public void RegisterNestedType<T>(Action<NetDataWriter, T> writer, Func<NetDataReader, T> reader)
Parameters
Type Name Description
Action<NetDataWriter, T> writer

custom type writer

Func<NetDataReader, T> reader

custom type reader

Type Parameters
Name Description
T

Any packet

RegisterNestedType<T>(Func<T>)

Register custom property type

Declaration
public void RegisterNestedType<T>(Func<T> constructor) where T : class, INetSerializable
Parameters
Type Name Description
Func<T> constructor
Type Parameters
Name Description
T

INetSerializable class

Register<T>()

Declaration
public void Register<T>()
Type Parameters
Name Description
T
Exceptions
Type Condition
InvalidTypeException

T's fields are not supported, or it has no fields

Serialize<T>(NetDataWriter, T)

Serialize object to NetDataWriter (fast)

Declaration
public void Serialize<T>(NetDataWriter writer, T obj) where T : class, new()
Parameters
Type Name Description
NetDataWriter writer

Serialization target NetDataWriter

T obj

Object to serialize

Type Parameters
Name Description
T
Exceptions
Type Condition
InvalidTypeException

T's fields are not supported, or it has no fields

Serialize<T>(T)

Serialize object to byte array

Declaration
public byte[] Serialize<T>(T obj) where T : class, new()
Parameters
Type Name Description
T obj

Object to serialize

Returns
Type Description
byte[]

byte array with serialized data

Type Parameters
Name Description
T
In this article
Back to top Generated by DocFX