Class ByteBuffer
public class ByteBuffer : IByteBuffer
- Inheritance
-
ByteBuffer
- Implements
- Inherited Members
Constructors
ByteBuffer(byte[])
Initialises the byte buffer with an existing buffer of data.
public ByteBuffer(byte[] data)
Parameters
databyte[]
ByteBuffer(int)
Initialises the byte buffer so it can be filled up to size bytes.
public ByteBuffer(int size)
Parameters
sizeint
Properties
Data
Buffer data.
public IReadOnlyList<byte> Data { get; }
Property Value
DataSpan
Span version of Data.
public ReadOnlySpan<byte> DataSpan { get; }
Property Value
Position
Cursor position.
public int Position { get; }
Property Value
Methods
Advance(int)
Advances the cursor bytes number of bytes.
public void Advance(int bytes)
Parameters
bytesint
ReadBool()
Reads a boolean value and advances 1 byte.
public bool ReadBool()
Returns
ReadChar()
Reads an ASCII character value and advances 1 byte.
public char ReadChar()
Returns
ReadEnum<T>()
Reads an enum value and advances 1 byte.
public T ReadEnum<T>() where T : struct, Enum
Returns
- T
Type Parameters
T
ReadF16()
Reads a half-precision float value and advances 2 bytes.
public Half ReadF16()
Returns
ReadF32()
Reads a single-precision float value and advances 4 bytes.
public float ReadF32()
Returns
ReadF64()
Reads a double-precision float value and advances 8 bytes.
public double ReadF64()
Returns
ReadI16()
Reads a signed short value and advances 2 bytes.
public short ReadI16()
Returns
ReadI32()
Reads a signed integer value and advances 4 bytes.
public int ReadI32()
Returns
ReadI64()
Reads a signed long value and advances 8 bytes.
public long ReadI64()
Returns
ReadObject<T>()
Reads/deserialises an object that implements IByteSerialisable.
public T ReadObject<T>() where T : IByteSerialisable, new()
Returns
- T
Type Parameters
T
ReadString(Encoding, StringLength)
Reads a string from the buffer.
public string ReadString(Encoding stringEncoding, StringLength stringLength)
Parameters
stringEncodingEncodingWhat type of encoding to use.
stringLengthStringLengthChoose between 256 (Short), 65k (Medium) and 2B max characters (Long).
Returns
Exceptions
ReadStringAscii(StringLength)
Reads an ASCII-encoded string from the buffer.
public string ReadStringAscii(StringLength stringLength)
Parameters
stringLengthStringLength
Returns
ReadStringUtf8(StringLength)
Reads a UTF-8-encoded string from the buffer.
public string ReadStringUtf8(StringLength stringLength)
Parameters
stringLengthStringLength
Returns
ReadU16()
Reads an unsigned short value and advances 2 bytes.
public ushort ReadU16()
Returns
ReadU32()
Reads an unsigned integer value and advances 4 bytes.
public uint ReadU32()
Returns
ReadU64()
Reads an unsigned long value and advances 8 bytes.
public ulong ReadU64()
Returns
ReadU8()
Reads an unsigned byte value and advances 1 byte.
public byte ReadU8()
Returns
Read<T>()
Reads generic data from the buffer.
public T Read<T>() where T : unmanaged
Returns
- T
Type Parameters
TThe type of data that gets read.
ResetData()
Clears the data buffer.
public void ResetData()
ResetPosition()
Resets the cursor to the beginning of the buffer.
public void ResetPosition()
WriteBool(bool)
Writes a boolean value and advances 1 byte.
public void WriteBool(bool value)
Parameters
valuebool
WriteChar(char)
Writes an ASCII character value and advances 1 byte.
public void WriteChar(char value)
Parameters
valuechar
WriteEnum<T>(T)
Writes an enum value and advances 1 byte.
public void WriteEnum<T>(T value) where T : struct, Enum, IConvertible
Parameters
valueT
Type Parameters
T
WriteF16(Half)
Writes a half-precision float value and advances 2 bytes.
public void WriteF16(Half value)
Parameters
valueHalf
WriteF32(float)
Writes a single-precision float value and advances 4 bytes.
public void WriteF32(float value)
Parameters
valuefloat
WriteF64(double)
Writes a double-precision float value and advances 8 bytes.
public void WriteF64(double value)
Parameters
valuedouble
WriteI16(short)
Writes a signed short value and advances 2 bytes.
public void WriteI16(short value)
Parameters
valueshort
WriteI32(int)
Writes a signed integer value and advances 4 bytes.
public void WriteI32(int value)
Parameters
valueint
WriteI64(long)
Writes a signed long value and advances 8 bytes.
public void WriteI64(long value)
Parameters
valuelong
WriteObject<T>(T)
Writes/serialises an object that implements IByteSerialisable.
public void WriteObject<T>(T value) where T : IByteSerialisable
Parameters
valueT
Type Parameters
T
WriteString(string, Encoding, StringLength)
Writes a string in the format: number of characters, raw string contents.
public void WriteString(string value, Encoding stringEncoding, StringLength stringLength)
Parameters
valuestringThe value to encode.
stringEncodingEncodingWhat type of string encoding to use (ASCII, UTF-8).
stringLengthStringLengthChoose between 256 (Short), 65k (Medium) and 2B max characters (Long).
WriteStringAscii(string, StringLength)
Writes an ASCII-encoded string.
public void WriteStringAscii(string value, StringLength stringLength)
Parameters
valuestringstringLengthStringLength
WriteStringUtf8(string, StringLength)
Writes a UTF-8-encoded string.
public void WriteStringUtf8(string value, StringLength stringLength)
Parameters
valuestringstringLengthStringLength
WriteU16(ushort)
Writes an unsigned short value and advances 2 bytes.
public void WriteU16(ushort value)
Parameters
valueushort
WriteU32(uint)
Writes an unsigned integer value and advances 4 bytes.
public void WriteU32(uint value)
Parameters
valueuint
WriteU64(ulong)
Writes an unsigned long value and advances 8 bytes.
public void WriteU64(ulong value)
Parameters
valueulong
WriteU8(byte)
Writes an unsigned byte value and advances 1 byte.
public void WriteU8(byte value)
Parameters
valuebyte
Write<T>(T)
Writes generic data into the buffer.
public void Write<T>(T value) where T : unmanaged
Parameters
valueT
Type Parameters
TThe type of data that gets written.