Skip to main content

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​
TypeNameDescription
System.Int32minByteCapacity

NetworkWriter(Int32, Boolean)​

Declaration​
public NetworkWriter(int minByteCapacity, bool allowResize)
Parameters​
TypeNameDescription
System.Int32minByteCapacity
System.BooleanallowResize

Fields​

StringStore​

Declaration​
public StringStore StringStore

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​
public void Reset()

ToArray()​

Copies internal buffer to new Array To reduce Allocations use instead

Declaration​
public byte[] ToArray()
Returns​
TypeDescription
System.Byte[]

ToArraySegment()​

Declaration​
public ArraySegment<byte> ToArraySegment()
Returns​
TypeDescription
System.ArraySegment<System.Byte>

PadToByte()​

Declaration​
public void PadToByte()

WriteBoolean(Boolean)​

Declaration​
public void WriteBoolean(bool value)
Parameters​
TypeNameDescription
System.Booleanvalue

WriteBoolean(UInt64)​

Writes first bit of value to buffer

Declaration​
public void WriteBoolean(ulong value)
Parameters​
TypeNameDescription
System.UInt64value

WriteSByte(SByte)​

Declaration​
public void WriteSByte(sbyte value)
Parameters​
TypeNameDescription
System.SBytevalue

WriteByte(Byte)​

Declaration​
public void WriteByte(byte value)
Parameters​
TypeNameDescription
System.Bytevalue

WriteInt16(Int16)​

Declaration​
public void WriteInt16(short value)
Parameters​
TypeNameDescription
System.Int16value

WriteUInt16(UInt16)​

Declaration​
public void WriteUInt16(ushort value)
Parameters​
TypeNameDescription
System.UInt16value

WriteInt32(Int32)​

Declaration​
public void WriteInt32(int value)
Parameters​
TypeNameDescription
System.Int32value

WriteUInt32(UInt32)​

Declaration​
public void WriteUInt32(uint value)
Parameters​
TypeNameDescription
System.UInt32value

WriteInt64(Int64)​

Declaration​
public void WriteInt64(long value)
Parameters​
TypeNameDescription
System.Int64value

WriteUInt64(UInt64)​

Declaration​
public void WriteUInt64(ulong value)
Parameters​
TypeNameDescription
System.UInt64value

WriteSingle(Single)​

Declaration​
public void WriteSingle(float value)
Parameters​
TypeNameDescription
System.Singlevalue

WriteDouble(Double)​

Declaration​
public void WriteDouble(double value)
Parameters​
TypeNameDescription
System.Doublevalue

Write(UInt64, Int32)​

Declaration​
public void Write(ulong value, int bits)
Parameters​
TypeNameDescription
System.UInt64value
System.Int32bits

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​
TypeNameDescription
System.UInt64value
System.Int32bits
System.Int32bytePosition

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​
TypeNameDescription
System.UInt64valuevalue to write
System.Int32bitsnumber of bits in value to write
System.Int32bitPositionwhere 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​
TypeNameDescription
System.Int32newPosition

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​
TypeNameDescription
Tvalue

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​
TypeNameDescription
System.Byte[]array
System.Int32offset
System.Int32length

WriteSpanRaw(ReadOnlySpan<Byte>)​

Moves position to nearest byte then copies span to that position

Declaration​
public void WriteSpanRaw(ReadOnlySpan<byte> span)
Parameters​
TypeNameDescription
ReadOnlySpan<System.Byte>span

CopyFromWriter(NetworkWriter)​

Copies all data from other

Declaration​
public void CopyFromWriter(NetworkWriter other)
Parameters​
TypeNameDescription
Mirage.Serialization.NetworkWriterother

CopyFromWriter(NetworkWriter, Int32, Int32)​

Copies bitLength bits from other starting at otherBitPosition

Declaration​
public void CopyFromWriter(NetworkWriter other, int otherBitPosition, int bitLength)
Parameters​
TypeNameDescription
Mirage.Serialization.NetworkWriterother
System.Int32otherBitPosition
System.Int32bitLength

CopyFromPointer(Void*, Int32, Int32)​

Copies bitLength bits from ptr starting at otherBitPosition

Declaration​
public void CopyFromPointer(void *ptr, int otherBitPosition, int bitLength)
Parameters​
TypeNameDescription
System.Void*ptr
System.Int32otherBitPosition
System.Int32bitLength