Show / Hide Table of Contents

# Class NetDataWriter

##### Inheritance

object
NetDataWriter

###### Namespace: LiteNetLib.Utils

###### Assembly: LiteNetLib.dll

##### Syntax

    public class NetDataWriter

### Constructors

#### NetDataWriter()

##### Declaration

    public NetDataWriter()

#### NetDataWriter(bool)

##### Declaration

    public NetDataWriter(bool autoResize)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | autoResize |

#### NetDataWriter(bool, int)

##### Declaration

    public NetDataWriter(bool autoResize, int initialSize)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | autoResize |
int | initialSize |

### Fields

#### StringBufferMaxLength

##### Declaration

    public const int StringBufferMaxLength = 65535

##### Field Value

Type | Description
--- | ---
int |

#### _data

##### Declaration

    protected byte[] _data

##### Field Value

Type | Description
--- | ---
byte[] |

#### _position

##### Declaration

    protected int _position

##### Field Value

Type | Description
--- | ---
int |

#### uTF8Encoding

##### Declaration

    public static readonly ThreadLocal<UTF8Encoding> uTF8Encoding

##### Field Value

Type | Description
--- | ---
ThreadLocal<UTF8Encoding> |

### Properties

#### Capacity

##### Declaration

    public int Capacity { get; }

##### Property Value

Type | Description
--- | ---
int |

#### Data

##### Declaration

    public byte[] Data { get; }

##### Property Value

Type | Description
--- | ---
byte[] |

#### Length

##### Declaration

    public int Length { get; }

##### Property Value

Type | Description
--- | ---
int |

### Methods

#### CopyData()

##### Declaration

    public byte[] CopyData()

##### Returns

Type | Description
--- | ---
byte[] |

#### EnsureFit(int)

##### Declaration

    public void EnsureFit(int additionalSize)

##### Parameters

Type | Name | Description
--- | --- | ---
int | additionalSize |

#### FromBytes(byte[], bool)

Creates NetDataWriter from existing ByteArray

##### Declaration

    public static NetDataWriter FromBytes(byte[] bytes, bool copy)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | bytes | Source byte array
bool | copy | Copy array to new location or use existing

##### Returns

Type | Description
--- | ---
NetDataWriter |

#### FromBytes(byte[], int, int)

Creates NetDataWriter from existing ByteArray (always copied data)

##### Declaration

    public static NetDataWriter FromBytes(byte[] bytes, int offset, int length)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | bytes | Source byte array
int | offset | Offset of array
int | length | Length of array

##### Returns

Type | Description
--- | ---
NetDataWriter |

#### FromString(string)

##### Declaration

    public static NetDataWriter FromString(string value)

##### Parameters

Type | Name | Description
--- | --- | ---
string | value |

##### Returns

Type | Description
--- | ---
NetDataWriter |

#### Put(bool)

##### Declaration

    public void Put(bool value)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | value |

#### Put(byte)

##### Declaration

    public void Put(byte value)

##### Parameters

Type | Name | Description
--- | --- | ---
byte | value |

#### Put(byte[])

##### Declaration

    public void Put(byte[] data)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | data |

#### Put(byte[], int, int)

##### Declaration

    public void Put(byte[] data, int offset, int length)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | data |
int | offset |
int | length |

#### Put(char)

##### Declaration

    public void Put(char value)

##### Parameters

Type | Name | Description
--- | --- | ---
char | value |

#### Put(double)

##### Declaration

    public void Put(double value)

##### Parameters

Type | Name | Description
--- | --- | ---
double | value |

#### Put(short)

##### Declaration

    public void Put(short value)

##### Parameters

Type | Name | Description
--- | --- | ---
short | value |

#### Put(int)

##### Declaration

    public void Put(int value)

##### Parameters

Type | Name | Description
--- | --- | ---
int | value |

#### Put(long)

##### Declaration

    public void Put(long value)

##### Parameters

Type | Name | Description
--- | --- | ---
long | value |

#### Put(IPEndPoint)

##### Declaration

    public void Put(IPEndPoint endPoint)

##### Parameters

Type | Name | Description
--- | --- | ---
IPEndPoint | endPoint |

#### Put(sbyte)

##### Declaration

    public void Put(sbyte value)

##### Parameters

Type | Name | Description
--- | --- | ---
sbyte | value |

#### Put(float)

##### Declaration

    public void Put(float value)

##### Parameters

Type | Name | Description
--- | --- | ---
float | value |

#### Put(string)

##### Declaration

    public void Put(string value)

##### Parameters

Type | Name | Description
--- | --- | ---
string | value |

#### Put(string, int)

Note that "maxLength" only limits the number of characters in a string, not its size in bytes.

##### Declaration

    public void Put(string value, int maxLength)

##### Parameters

Type | Name | Description
--- | --- | ---
string | value |
int | maxLength |

#### Put(ushort)

##### Declaration

    public void Put(ushort value)

##### Parameters

Type | Name | Description
--- | --- | ---
ushort | value |

#### Put(uint)

##### Declaration

    public void Put(uint value)

##### Parameters

Type | Name | Description
--- | --- | ---
uint | value |

#### Put(ulong)

##### Declaration

    public void Put(ulong value)

##### Parameters

Type | Name | Description
--- | --- | ---
ulong | value |

#### PutArray(Array, int)

##### Declaration

    public void PutArray(Array arr, int sz)

##### Parameters

Type | Name | Description
--- | --- | ---
Array | arr |
int | sz |

#### PutArray(bool[])

##### Declaration

    public void PutArray(bool[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
bool[] | value |

#### PutArray(double[])

##### Declaration

    public void PutArray(double[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
double[] | value |

#### PutArray(short[])

##### Declaration

    public void PutArray(short[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
short[] | value |

#### PutArray(int[])

##### Declaration

    public void PutArray(int[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
int[] | value |

#### PutArray(long[])

##### Declaration

    public void PutArray(long[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
long[] | value |

#### PutArray(float[])

##### Declaration

    public void PutArray(float[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
float[] | value |

#### PutArray(string[])

##### Declaration

    public void PutArray(string[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
string[] | value |

#### PutArray(string[], int)

##### Declaration

    public void PutArray(string[] value, int strMaxLength)

##### Parameters

Type | Name | Description
--- | --- | ---
string[] | value |
int | strMaxLength |

#### PutArray(ushort[])

##### Declaration

    public void PutArray(ushort[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
ushort[] | value |

#### PutArray(uint[])

##### Declaration

    public void PutArray(uint[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
uint[] | value |

#### PutArray(ulong[])

##### Declaration

    public void PutArray(ulong[] value)

##### Parameters

Type | Name | Description
--- | --- | ---
ulong[] | value |

#### PutBytesWithLength(byte[])

##### Declaration

    public void PutBytesWithLength(byte[] data)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | data |

#### PutBytesWithLength(byte[], int, ushort)

##### Declaration

    public void PutBytesWithLength(byte[] data, int offset, ushort length)

##### Parameters

Type | Name | Description
--- | --- | ---
byte[] | data |
int | offset |
ushort | length |

#### PutSBytesWithLength(sbyte[])

##### Declaration

    public void PutSBytesWithLength(sbyte[] data)

##### Parameters

Type | Name | Description
--- | --- | ---
sbyte[] | data |

#### PutSBytesWithLength(sbyte[], int, ushort)

##### Declaration

    public void PutSBytesWithLength(sbyte[] data, int offset, ushort length)

##### Parameters

Type | Name | Description
--- | --- | ---
sbyte[] | data |
int | offset |
ushort | length |

#### Put<T>(T)

##### Declaration

    public void Put<T>(T obj) where T : INetSerializable

##### Parameters

Type | Name | Description
--- | --- | ---
T | obj |

##### Type Parameters

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

#### Reset()

##### Declaration

    public void Reset()

#### Reset(int)

##### Declaration

    public void Reset(int size)

##### Parameters

Type | Name | Description
--- | --- | ---
int | size |

#### ResizeIfNeed(int)

##### Declaration

    public void ResizeIfNeed(int newSize)

##### Parameters

Type | Name | Description
--- | --- | ---
int | newSize |

#### SetPosition(int)

Sets position of NetDataWriter to rewrite previous values

##### Declaration

    public int SetPosition(int position)

##### Parameters

Type | Name | Description
--- | --- | ---
int | position | new byte position

##### Returns

Type | Description
--- | ---
int | previous position of data writer