Show / Hide Table of Contents

# Class NetPacketProcessor

##### Inheritance

object
NetPacketProcessor

###### Namespace: LiteNetLib.Utils

###### Assembly: LiteNetLib.dll

##### Syntax

    public class NetPacketProcessor

### Constructors

#### NetPacketProcessor()

##### Declaration

    public NetPacketProcessor()

#### NetPacketProcessor(int)

##### Declaration

    public NetPacketProcessor(int maxStringLength)

##### Parameters

Type | Name | Description
--- | --- | ---
int | maxStringLength |

### Methods

#### GetCallbackFromData(NetDataReader)

##### Declaration

    protected virtual NetPacketProcessor.SubscribeDelegate GetCallbackFromData(NetDataReader reader)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataReader | reader |

##### Returns

Type | Description
--- | ---
NetPacketProcessor.SubscribeDelegate |

#### GetHash<T>()

##### Declaration

    protected virtual ulong GetHash<T>()

##### Returns

Type | Description
--- | ---
ulong |

##### Type Parameters

Name | Description
--- | ---
T |

#### ReadAllPackets(NetDataReader)

Reads all available data from NetDataReader and calls OnReceive delegates

##### Declaration

    public void ReadAllPackets(NetDataReader reader)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataReader | reader | NetDataReader with packets data

#### ReadAllPackets(NetDataReader, object)

Reads all available data from NetDataReader and calls OnReceive delegates

##### Declaration

    public void ReadAllPackets(NetDataReader reader, object userData)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataReader | reader | NetDataReader with packets data
object | userData | Argument that passed to OnReceivedEvent

##### Exceptions

Type | Condition
--- | ---
ParseException | Malformed packet

#### ReadPacket(NetDataReader)

Reads one packet from NetDataReader and calls OnReceive delegate

##### Declaration

    public void ReadPacket(NetDataReader reader)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataReader | reader | NetDataReader with packet

##### Exceptions

Type | Condition
--- | ---
ParseException | Malformed packet

#### ReadPacket(NetDataReader, object)

Reads one packet from NetDataReader and calls OnReceive delegate

##### Declaration

    public void ReadPacket(NetDataReader reader, object userData)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataReader | reader | NetDataReader with packet
object | userData | Argument that passed to OnReceivedEvent

##### Exceptions

Type | Condition
--- | ---
ParseException | Malformed packet

#### RegisterNestedType<T>()

Register nested 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 nested property type

##### Declaration

    public void RegisterNestedType<T>(Action<NetDataWriter, T> writeDelegate, Func<NetDataReader, T> readDelegate)

##### Parameters

Type | Name | Description
--- | --- | ---
Action<NetDataWriter, T> | writeDelegate |
Func<NetDataReader, T> | readDelegate |

##### Type Parameters

Name | Description
--- | ---
T |

#### RegisterNestedType<T>(Func<T>)

Register nested 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

#### RemoveSubscription<T>()

Remove any subscriptions by type

##### Declaration

    public bool RemoveSubscription<T>()

##### Returns

Type | Description
--- | ---
bool | true if remove is success

##### Type Parameters

Name | Description
--- | ---
T | Packet type

#### SubscribeNetSerializable<T>(Action<T>)

##### Declaration

    public void SubscribeNetSerializable<T>(Action<T> onReceive) where T : INetSerializable, new()

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | onReceive |

##### Type Parameters

Name | Description
--- | ---
T |

#### SubscribeNetSerializable<T>(Action<T>, Func<T>)

##### Declaration

    public void SubscribeNetSerializable<T>(Action<T> onReceive, Func<T> packetConstructor) where T : INetSerializable

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | onReceive |
Func<T> | packetConstructor |

##### Type Parameters

Name | Description
--- | ---
T |

#### SubscribeNetSerializable<T, TUserData>(Action<T, TUserData>)

##### Declaration

    public void SubscribeNetSerializable<T, TUserData>(Action<T, TUserData> onReceive) where T : INetSerializable, new()

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T, TUserData> | onReceive |

##### Type Parameters

Name | Description
--- | ---
T |
TUserData |

#### SubscribeNetSerializable<T, TUserData>(Action<T, TUserData>, Func<T>)

##### Declaration

    public void SubscribeNetSerializable<T, TUserData>(Action<T, TUserData> onReceive, Func<T> packetConstructor) where T : INetSerializable

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T, TUserData> | onReceive |
Func<T> | packetConstructor |

##### Type Parameters

Name | Description
--- | ---
T |
TUserData |

#### SubscribeReusable<T>(Action<T>)

Register and subscribe to packet receive event This method will overwrite last received packet class on receive (less garbage)

##### Declaration

    public void SubscribeReusable<T>(Action<T> onReceive) where T : class, new()

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | onReceive | event that will be called when packet deserialized with ReadPacket method

##### Type Parameters

Name | Description
--- | ---
T |

##### Exceptions

Type | Condition
--- | ---
InvalidTypeException | `T`'s fields are not supported, or it has no fields

#### SubscribeReusable<T, TUserData>(Action<T, TUserData>)

Register and subscribe to packet receive event This method will overwrite last received packet class on receive (less garbage)

##### Declaration

    public void SubscribeReusable<T, TUserData>(Action<T, TUserData> onReceive) where T : class, new()

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T, TUserData> | onReceive | event that will be called when packet deserialized with ReadPacket method

##### Type Parameters

Name | Description
--- | ---
T |
TUserData |

##### Exceptions

Type | Condition
--- | ---
InvalidTypeException | `T`'s fields are not supported, or it has no fields

#### Subscribe<T>(Action<T>, Func<T>)

Register and subscribe to packet receive event

##### Declaration

    public void Subscribe<T>(Action<T> onReceive, Func<T> packetConstructor) where T : class, new()

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | onReceive | event that will be called when packet deserialized with ReadPacket method
Func<T> | packetConstructor | Method that constructs packet instead of slow Activator.CreateInstance

##### Type Parameters

Name | Description
--- | ---
T |

##### Exceptions

Type | Condition
--- | ---
InvalidTypeException | `T`'s fields are not supported, or it has no fields

#### Subscribe<T, TUserData>(Action<T, TUserData>, Func<T>)

Register and subscribe to packet receive event (with userData)

##### Declaration

    public void Subscribe<T, TUserData>(Action<T, TUserData> onReceive, Func<T> packetConstructor) where T : class, new()

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T, TUserData> | onReceive | event that will be called when packet deserialized with ReadPacket method
Func<T> | packetConstructor | Method that constructs packet instead of slow Activator.CreateInstance

##### Type Parameters

Name | Description
--- | ---
T |
TUserData |

##### Exceptions

Type | Condition
--- | ---
InvalidTypeException | `T`'s fields are not supported, or it has no fields

#### WriteHash<T>(NetDataWriter)

##### Declaration

    protected virtual void WriteHash<T>(NetDataWriter writer)

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataWriter | writer |

##### Type Parameters

Name | Description
--- | ---
T |

#### WriteNetSerializable<T>(NetDataWriter, ref T)

##### Declaration

    public void WriteNetSerializable<T>(NetDataWriter writer, ref T packet) where T : INetSerializable

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataWriter | writer |
T | packet |

##### Type Parameters

Name | Description
--- | ---
T |

#### Write<T>(NetDataWriter, T)

##### Declaration

    public void Write<T>(NetDataWriter writer, T packet) where T : class, new()

##### Parameters

Type | Name | Description
--- | --- | ---
NetDataWriter | writer |
T | packet |

##### Type Parameters

Name | Description
--- | ---
T |