Class NetworkWriter
Bit writer, writes values to a buffer on a bit level
Use to reduce memory allocation
Inheritance
System.Object
Inherited Members
Show
Syntax
public class NetworkWriter
Constructors
NetworkWriter(Int32)
Declaration
public NetworkWriter(int minByteCapacity)
Parameters
Type | Name | Description |
---|
System.Int32 | minByteCapacity | |
NetworkWriter(Int32, Boolean)
Declaration
public NetworkWriter(int minByteCapacity, bool allowResize)
Parameters
Type | Name | Description |
---|
System.Int32 | minByteCapacity | |
System.Boolean | allowResize | |
Properties
ByteCapacity
Size limit of buffer
Declaration
public int ByteCapacity { get; }
ByteLength
Current rounded up to nearest multiple of 8
To set byte position use multiple by 8
Declaration
public int ByteLength { get; }
BitPosition
Current bit position for writing to buffer
To set bit position use
Declaration
public int BitPosition { get; }
Methods
Finalize()
Declaration
protected void Finalize()
Reset()
Declaration
ToArray()
Copies internal buffer to new Array
To reduce Allocations use instead
Declaration
Returns
Type | Description |
---|
System.Byte[] | |
ToArraySegment()
Declaration
public ArraySegment<byte> ToArraySegment()
Returns
Type | Description |
---|
System.ArraySegment<System.Byte> | |
PadToByte()
Declaration
WriteBoolean(Boolean)
Declaration
public void WriteBoolean(bool value)
Parameters
Type | Name | Description |
---|
System.Boolean | value | |
WriteBoolean(UInt64)
Writes first bit of value to buffer
Declaration
public void WriteBoolean(ulong value)
Parameters
Type | Name | Description |
---|
System.UInt64 | value | |
WriteSByte(SByte)
Declaration
public void WriteSByte(sbyte value)
Parameters
Type | Name | Description |
---|
System.SByte | value | |
WriteByte(Byte)
Declaration
public void WriteByte(byte value)
Parameters
Type | Name | Description |
---|
System.Byte | value | |
WriteInt16(Int16)
Declaration
public void WriteInt16(short value)
Parameters
Type | Name | Description |
---|
System.Int16 | value | |
WriteUInt16(UInt16)
Declaration
public void WriteUInt16(ushort value)
Parameters
Type | Name | Description |
---|
System.UInt16 | value | |
WriteInt32(Int32)
Declaration
public void WriteInt32(int value)
Parameters
Type | Name | Description |
---|
System.Int32 | value | |
WriteUInt32(UInt32)
Declaration
public void WriteUInt32(uint value)
Parameters
Type | Name | Description |
---|
System.UInt32 | value | |
WriteInt64(Int64)
Declaration
public void WriteInt64(long value)
Parameters
Type | Name | Description |
---|
System.Int64 | value | |
WriteUInt64(UInt64)
Declaration
public void WriteUInt64(ulong value)
Parameters
Type | Name | Description |
---|
System.UInt64 | value | |
WriteSingle(Single)
Declaration
public void WriteSingle(float value)
Parameters
Type | Name | Description |
---|
System.Single | value | |
WriteDouble(Double)
Declaration
public void WriteDouble(double value)
Parameters
Type | Name | Description |
---|
System.Double | value | |
Write(UInt64, Int32)
Declaration
public void Write(ulong value, int bits)
Parameters
Type | Name | Description |
---|
System.UInt64 | value | |
System.Int32 | bits | |
WriteAtBytePosition(UInt64, Int32, Int32)
Same as expect position given is in bytes instead of bits
WARNING: When writing to bytes instead of bits make sure you are able to read at the right position when deserializing as it might cause data to be misaligned
Declaration
public void WriteAtBytePosition(ulong value, int bits, int bytePosition)
Parameters
Type | Name | Description |
---|
System.UInt64 | value | |
System.Int32 | bits | |
System.Int32 | bytePosition | |
WriteAtPosition(UInt64, Int32, Int32)
Writes n bits from value to bitPosition
This methods can be used to go back to a previous position to write length or other flags to the buffer after other data has been written
WARNING: This method does not change the internal position so will not change the overall length if writing past internal position
Declaration
public void WriteAtPosition(ulong value, int bits, int bitPosition)
Parameters
Type | Name | Description |
---|
System.UInt64 | value | value to write |
System.Int32 | bits | number of bits in value to write |
System.Int32 | bitPosition | where to write bits |
MoveBitPosition(Int32)
Moves the internal bit position
For most usecases it is safer to use
WARNING: When writing to earlier position make sure to move position back to end of buffer after writing because position is also used as length
Declaration
public void MoveBitPosition(int newPosition)
Parameters
Type | Name | Description |
---|
System.Int32 | newPosition | |
PadAndCopy<T>(T)
Moves position to nearest byte then copies struct to that position
Declaration
public void PadAndCopy<T>(in T value)
where T : struct
Parameters
Type | Name | Description |
---|
T | value | |
WriteBytes(Byte[], Int32, Int32)
Moves position to nearest byte then writes bytes to that position
Declaration
public void WriteBytes(byte[] array, int offset, int length)
Parameters
Type | Name | Description |
---|
System.Byte[] | array | |
System.Int32 | offset | |
System.Int32 | length | |
CopyFromWriter(NetworkWriter)
Copies all data from other
Declaration
public void CopyFromWriter(NetworkWriter other)
Parameters
Type | Name | Description |
---|
Mirage.Serialization.NetworkWriter | other | |
CopyFromWriter(NetworkWriter, Int32, Int32)
Copies bitLength bits from other starting at otherBitPosition
Declaration
public void CopyFromWriter(NetworkWriter other, int otherBitPosition, int bitLength)
Parameters
Type | Name | Description |
---|
Mirage.Serialization.NetworkWriter | other | |
System.Int32 | otherBitPosition | |
System.Int32 | bitLength | |
CopyFromPointer(Void*, Int32, Int32)
Copies bitLength bits from ptr starting at otherBitPosition
Declaration
public void CopyFromPointer(void *ptr, int otherBitPosition, int bitLength)
Parameters
Type | Name | Description |
---|
System.Void* | ptr | |
System.Int32 | otherBitPosition | |
System.Int32 | bitLength | |