Class ByteBufferHelper
Helper class for dealing with a byte buffer of a specified size. You can write various primitives to the buffer and then get the final size and buffer for usage before resetting it for further use. Helps avoid additional allocations. Intended for internal usage by Alacrity, but very generic and can be used anywhere.
public class ByteBufferHelper
- Inheritance
-
ByteBufferHelper
- Inherited Members
Constructors
ByteBufferHelper(int)
Create a new byte buffer helper with a given size.
public ByteBufferHelper(int bufferSize)
Parameters
bufferSize
int
Methods
GetBytes()
Get the full buffer
public byte[] GetBytes()
Returns
- byte[]
GetLength()
Get length of the buffer thus far. If you just called Reset, this will be 0. If you've added a single int, this will be 4.
public int GetLength()
Returns
Reset()
Reset the buffer.
public void Reset()
WriteByte(byte)
Write a single byte to the buffer.
public void WriteByte(byte b)
Parameters
b
byte
WriteInt(int)
Write an int to the buffer using big-endian encoding.
public void WriteInt(int i)
Parameters
i
int
WriteString(string)
Write a string to the buffer using ASCII encoding.
public void WriteString(string s)
Parameters
s
string