Show / Hide Table of Contents

Class NetSerializer

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

Constructors

NetSerializer()

Declaration
public NetSerializer()

NetSerializer(Int32)

Declaration
public NetSerializer(int maxStringLength)
Parameters
Type Name Description
System.Int32 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
System.Boolean

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

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

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
System.Action<NetDataWriter, T> writer

custom type writer

System.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
System.Func<T> constructor
Type Parameters
Name Description
T

INetSerializable class

Serialize<T>(T)

Serialize struct 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
System.Byte[]

byte array with serialized data

Type Parameters
Name Description
T

Serialize<T>(NetDataWriter, T)

Serialize struct 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

Back to top Generated by DocFX