Interface IByteBuffer
- Namespace
- Elegy.Common.Interfaces
- Assembly
- Elegy.Common.dll
Byte buffer, a container that you can use to conveniently read from and write to binary blobs of data.
public interface IByteBuffer
Properties
Data
Buffer data.
IReadOnlyList<byte> Data { get; }
Property Value
DataSpan
Span version of Data.
ReadOnlySpan<byte> DataSpan { get; }
Property Value
Position
Cursor position.
int Position { get; }
Property Value
Methods
Advance(int)
Advances the cursor bytes
number of bytes.
void Advance(int bytes)
Parameters
bytes
int
ReadBool()
Reads a boolean value and advances 1 byte.
bool ReadBool()
Returns
ReadChar()
Reads an ASCII character value and advances 1 byte.
char ReadChar()
Returns
ReadEnum<T>()
Reads an enum value and advances 1 byte.
T ReadEnum<T>() where T : struct, Enum
Returns
- T
Type Parameters
T
ReadF16()
Reads a half-precision float value and advances 2 bytes.
Half ReadF16()
Returns
ReadF32()
Reads a single-precision float value and advances 4 bytes.
float ReadF32()
Returns
ReadF64()
Reads a double-precision float value and advances 8 bytes.
double ReadF64()
Returns
ReadI16()
Reads a signed short value and advances 2 bytes.
short ReadI16()
Returns
ReadI32()
Reads a signed integer value and advances 4 bytes.
int ReadI32()
Returns
ReadI64()
Reads a signed long value and advances 8 bytes.
long ReadI64()
Returns
ReadObject<T>()
Reads/deserialises an object that implements IByteSerialisable.
T ReadObject<T>() where T : IByteSerialisable, new()
Returns
- T
Type Parameters
T
ReadString(Encoding, StringLength)
Reads a string from the buffer.
string ReadString(Encoding stringEncoding, StringLength stringLength)
Parameters
stringEncoding
EncodingWhat type of encoding to use.
stringLength
StringLengthChoose between 256 (Short), 65k (Medium) and 2B max characters (Long).
Returns
Exceptions
ReadStringAscii(StringLength)
Reads an ASCII-encoded string from the buffer.
string ReadStringAscii(StringLength stringLength)
Parameters
stringLength
StringLength
Returns
ReadStringUtf8(StringLength)
Reads a UTF-8-encoded string from the buffer.
string ReadStringUtf8(StringLength stringLength)
Parameters
stringLength
StringLength
Returns
ReadU16()
Reads an unsigned short value and advances 2 bytes.
ushort ReadU16()
Returns
ReadU32()
Reads an unsigned integer value and advances 4 bytes.
uint ReadU32()
Returns
ReadU64()
Reads an unsigned long value and advances 8 bytes.
ulong ReadU64()
Returns
ReadU8()
Reads an unsigned byte value and advances 1 byte.
byte ReadU8()
Returns
Read<T>()
Reads generic data from the buffer.
T Read<T>() where T : unmanaged
Returns
- T
Type Parameters
T
The type of data that gets read.
ResetData()
Clears the data buffer.
void ResetData()
ResetPosition()
Resets the cursor to the beginning of the buffer.
void ResetPosition()
WriteBool(bool)
Writes a boolean value and advances 1 byte.
void WriteBool(bool value)
Parameters
value
bool
WriteChar(char)
Writes an ASCII character value and advances 1 byte.
void WriteChar(char value)
Parameters
value
char
WriteEnum<T>(T)
Writes an enum value and advances 1 byte.
void WriteEnum<T>(T value) where T : struct, Enum, IConvertible
Parameters
value
T
Type Parameters
T
WriteF16(Half)
Writes a half-precision float value and advances 2 bytes.
void WriteF16(Half value)
Parameters
value
Half
WriteF32(float)
Writes a single-precision float value and advances 4 bytes.
void WriteF32(float value)
Parameters
value
float
WriteF64(double)
Writes a double-precision float value and advances 8 bytes.
void WriteF64(double value)
Parameters
value
double
WriteI16(short)
Writes a signed short value and advances 2 bytes.
void WriteI16(short value)
Parameters
value
short
WriteI32(int)
Writes a signed integer value and advances 4 bytes.
void WriteI32(int value)
Parameters
value
int
WriteI64(long)
Writes a signed long value and advances 8 bytes.
void WriteI64(long value)
Parameters
value
long
WriteObject<T>(T)
Writes/serialises an object that implements IByteSerialisable.
void WriteObject<T>(T value) where T : IByteSerialisable
Parameters
value
T
Type Parameters
T
WriteString(string, Encoding, StringLength)
Writes a string in the format: number of characters, raw string contents.
void WriteString(string value, Encoding stringEncoding, StringLength stringLength)
Parameters
value
stringThe value to encode.
stringEncoding
EncodingWhat type of string encoding to use (ASCII, UTF-8).
stringLength
StringLengthChoose between 256 (Short), 65k (Medium) and 2B max characters (Long).
WriteStringAscii(string, StringLength)
Writes an ASCII-encoded string.
void WriteStringAscii(string value, StringLength stringLength)
Parameters
value
stringstringLength
StringLength
WriteStringUtf8(string, StringLength)
Writes a UTF-8-encoded string.
void WriteStringUtf8(string value, StringLength stringLength)
Parameters
value
stringstringLength
StringLength
WriteU16(ushort)
Writes an unsigned short value and advances 2 bytes.
void WriteU16(ushort value)
Parameters
value
ushort
WriteU32(uint)
Writes an unsigned integer value and advances 4 bytes.
void WriteU32(uint value)
Parameters
value
uint
WriteU64(ulong)
Writes an unsigned long value and advances 8 bytes.
void WriteU64(ulong value)
Parameters
value
ulong
WriteU8(byte)
Writes an unsigned byte value and advances 1 byte.
void WriteU8(byte value)
Parameters
value
byte
Write<T>(T)
Writes generic data into the buffer.
void Write<T>(T value) where T : unmanaged
Parameters
value
T
Type Parameters
T
The type of data that gets written.