Skip to main content

MLAPI.Serialization.NetworkBuffer

A buffer that can be used at the bit level

Inheritance#

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

System.Dynamic.ExpandoObject

Implements#

System.IDisposable

Inherited Members#

Stream.Null

Stream.BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

Stream.Close()

Stream.CreateWaitHandle()

Stream.Dispose()

Stream.Dispose(Boolean)

Stream.EndRead(IAsyncResult)

Stream.EndWrite(IAsyncResult)

Stream.Synchronized(Stream)

Stream.CanTimeout

Stream.ReadTimeout

Stream.WriteTimeout

MarshalByRefObject.CreateObjRef(Type)

MarshalByRefObject.GetLifetimeService()

MarshalByRefObject.InitializeLifetimeService()

MarshalByRefObject.MemberwiseClone(Boolean)

Object.Equals(Object)

Object.Equals(Object, Object)

Object.GetHashCode()

Object.GetType()

Object.MemberwiseClone()

Object.ReferenceEquals(Object, Object)

Namespace: System.Dynamic.ExpandoObject#
Assembly: MLAPI.dll#
Syntax#
public class NetworkBuffer : Stream, IDisposable

Constructors#

NetworkBuffer()#

A buffer that supports writing data smaller than a single byte. This buffer also has a built-in compression algorithm that can (optionally) be used to write compressed data.

Declaration#

public NetworkBuffer()

NetworkBuffer(Byte[])#

A buffer that supports writing data smaller than a single byte. This buffer also has a built-in compression algorithm that can (optionally) be used to write compressed data. NOTE: when using a pre-allocated buffer, the buffer will not grow!

Declaration#

public NetworkBuffer(byte[] target)

Parameters#

TypeNameDescription
System.Byte[]targetPre-allocated buffer to write to

NetworkBuffer(Int32)#

A buffer that supports writing data smaller than a single byte. This buffer also has a built-in compression algorithm that can (optionally) be used to write compressed data.

Declaration#

public NetworkBuffer(int capacity)

Parameters#

TypeNameDescription
System.Int32capacity

NetworkBuffer(Int32, Single)#

A buffer that supports writing data smaller than a single byte. This buffer also has a built-in compression algorithm that can (optionally) be used to write compressed data.

Declaration#

public NetworkBuffer(int capacity, float growthFactor)

Parameters#

TypeNameDescription
System.Int32capacityInitial capacity of buffer in bytes.
System.SinglegrowthFactorFactor by which buffer should grow when necessary.

NetworkBuffer(Single)#

A buffer that supports writing data smaller than a single byte. This buffer also has a built-in compression algorithm that can (optionally) be used to write compressed data.

Declaration#

public NetworkBuffer(float growthFactor)

Parameters#

TypeNameDescription
System.SinglegrowthFactorFactor by which buffer should grow when necessary.

Properties#

BitAligned#

Whether or not the current BitPosition is evenly divisible by 8. I.e. whether or not the BitPosition is at a byte boundary.

Declaration#

public bool BitAligned { get; }

Property Value#

TypeDescription
System.Boolean

BitLength#

Length of data (in bits) that is considered to be written to the buffer.

Declaration#

public ulong BitLength { get; }

Property Value#

TypeDescription
System.UInt64

BitPosition#

Bit offset into the buffer that new data will be written to.

Declaration#

public ulong BitPosition { get; set; }

Property Value#

TypeDescription
System.UInt64

CanRead#

Whether or not buffeer supports reading. (Always true)

Declaration#

public override bool CanRead { get; }

Property Value#

TypeDescription
System.Boolean

Overrides#

System.IO.Stream.CanRead

CanSeek#

Whether or not seeking is supported by this buffer. (Always true)

Declaration#

public override bool CanSeek { get; }

Property Value#

TypeDescription
System.Boolean

Overrides#

System.IO.Stream.CanSeek

CanWrite#

Whether or not this buffer can accept new data. NOTE: this will return true even if only fewer than 8 bits can be written!

Declaration#

public override bool CanWrite { get; }

Property Value#

TypeDescription
System.Boolean

Overrides#

System.IO.Stream.CanWrite

Capacity#

Current buffer size. The buffer will not be resized (if possible) until Position is equal to Capacity and an attempt to write data is made.

Declaration#

public long Capacity { get; set; }

Property Value#

TypeDescription
System.Int64

GrowthFactor#

Factor by which buffer should grow when necessary.

Declaration#

public float GrowthFactor { get; set; }

Property Value#

TypeDescription
System.Single

HasDataToRead#

Whether or not or there is any data to be read from the buffer.

Declaration#

public bool HasDataToRead { get; }

Property Value#

TypeDescription
System.Boolean

Length#

The current length of data considered to be "written" to the buffer.

Declaration#

public override long Length { get; }

Property Value#

TypeDescription
System.Int64

Overrides#

System.IO.Stream.Length

Position#

The index that will be written to when any call to write data is made to this buffer.

Declaration#

public override long Position { get; set; }

Property Value#

TypeDescription
System.Int64

Overrides#

System.IO.Stream.Position

Resizable#

Whether or not the buffer will grow the buffer to accomodate more data.

Declaration#

public bool Resizable { get; }

Property Value#

TypeDescription
System.Boolean

Methods#

CopyFrom(NetworkBuffer, Int32, Boolean)#

Copys the bits from the provided NetworkBuffer

Declaration#

public void CopyFrom(NetworkBuffer buffer, int dataCount, bool copyBits)

Parameters#

TypeNameDescription
NetworkBufferbufferThe buffer to copy from
System.Int32dataCountThe amount of data evel
System.BooleancopyBitsWhether or not to copy at the bit level rather than the byte level

CopyFrom(Stream, Int32)#

Copy data from another stream

Declaration#

public void CopyFrom(Stream s, int count = -1)

Parameters#

TypeNameDescription
System.IO.StreamsStream to copy from
System.Int32countHow many bytes to read. Set to value less than one to read until ReadByte returns -1

CopyTo(Stream, Int32)#

Copies internal buffer to stream

Declaration#

public void CopyTo(Stream stream, int count = -1)

Parameters#

TypeNameDescription
System.IO.StreamstreamThe stream to copy to
System.Int32countThe maximum amount of bytes to copy. Set to value less than one to copy the full length

CopyUnreadFrom(Stream, Int32)#

Copies urnead bytes from the source stream

Declaration#

public void CopyUnreadFrom(Stream s, int count = -1)

Parameters#

TypeNameDescription
System.IO.StreamsThe source stream to copy from
System.Int32countThe max amount of bytes to copy

Flush()#

Flush buffer. This does nothing since data is written directly to a byte buffer.

Declaration#

public override void Flush()

Overrides#

System.IO.Stream.Flush()

GetBuffer()#

Get the internal buffer being written to by this buffer.

Declaration#

public byte[] GetBuffer()

Returns#

TypeDescription
System.Byte[]

PadBuffer()#

Writes zeros to fill the last byte

Declaration#

public void PadBuffer()

PeekByte()#

Peeks a byte without advancing the position

Declaration#

public int PeekByte()

Returns#

TypeDescription
System.Int32The peeked byte

Read(Byte[], Int32, Int32)#

Read a subset of the buffer buffer and write the contents to the supplied buffer.

Declaration#

public override int Read(byte[] buffer, int offset, int count)

Parameters#

TypeNameDescription
System.Byte[]bufferBuffer to copy data to.
System.Int32offsetOffset into the buffer to write data to.
System.Int32countHow many bytes to attempt to read.

Returns#

TypeDescription
System.Int32Amount of bytes read.

Overrides#

System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)

ReadBit()#

Read a single bit from the buffer.

Declaration#

public bool ReadBit()

Returns#

TypeDescription
System.BooleanA bit in bool format. (True represents 1, False represents 0)

ReadByte()#

Read a byte from the buffer. This takes into account possible byte misalignment.

Declaration#

public override int ReadByte()

Returns#

TypeDescription
System.Int32A byte from the buffer or, if a byte can't be read, -1.

Overrides#

System.IO.Stream.ReadByte()

Seek(Int64, SeekOrigin)#

Set position in buffer to read from/write to.

Declaration#

public override long Seek(long offset, SeekOrigin origin)

Parameters#

TypeNameDescription
System.Int64offsetOffset from position origin.
System.IO.SeekOriginoriginHow to calculate offset.

Returns#

TypeDescription
System.Int64The new position in the buffer that data will be written to.

Overrides#

System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)

SetLength(Int64)#

Set length of data considered to be "written" to the buffer.

Declaration#

public override void SetLength(long value)

Parameters#

TypeNameDescription
System.Int64valueNew length of the written data.

Overrides#

System.IO.Stream.SetLength(System.Int64)

SkipPadBits()#

Reads zeros until the the buffer is byte aligned

Declaration#

public void SkipPadBits()

ToArray()#

Creates a copy of the internal buffer. This only contains the used bytes

Declaration#

public byte[] ToArray()

Returns#

TypeDescription
System.Byte[]A copy of used bytes in the internal buffer

ToString()#

Returns hex encoded version of the buffer

Declaration#

public override string ToString()

Returns#

TypeDescription
System.StringHex encoded version of the buffer

Overrides#

System.Object.ToString()

Write(Byte[])#

Write data from the given buffer to the internal buffer.

Declaration#

public void Write(byte[] buffer)

Parameters#

TypeNameDescription
System.Byte[]bufferBuffer to write from.

Write(Byte[], Int32, Int32)#

Write data from the given buffer to the internal buffer.

Declaration#

public override void Write(byte[] buffer, int offset, int count)

Parameters#

TypeNameDescription
System.Byte[]bufferBuffer to write from.
System.Int32offsetOffset in given buffer to start reading from.
System.Int32countAmount of bytes to read copy from given buffer to buffer.

Overrides#

System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32)

WriteBit(Boolean)#

Write a single bit to the buffer

Declaration#

public void WriteBit(bool bit)

Parameters#

TypeNameDescription
System.BooleanbitValue of the bit. True represents 1, False represents 0

WriteByte(Byte)#

Write byte value to the internal buffer.

Declaration#

public override void WriteByte(byte value)

Parameters#

TypeNameDescription
System.BytevalueThe byte value to write.

Overrides#

System.IO.Stream.WriteByte(System.Byte)

Implements#

System.IDisposable