Buffer

Buffer for writing and reading binary data.

Constructors

this
this(size_t chunk)

Creates a buffer specifying the chunk size. This should be the default constructor for re-used buffers and input buffers.

this
this(T[] data)

Creates a buffer from an array of data. The chunk size is set to the size of the array.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

__xdtor
void __xdtor()
Undocumented in source. Be warned that the author may not have intended to support it.
back
void back(size_t amount)
Undocumented in source. Be warned that the author may not have intended to support it.
canRead
bool canRead(size_t size)
bool canRead()

Indicates whether an array of length size or the given type can be read without any exceptions thrown.

free
void free()
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(T[] data)

Check whether the data of the buffer is equals to the given array.

peek
T peek()

Peeks a value using the given endianness.

peek
T peek()

Peeks some data using the system's endianness.

peek
B peek()

Peeks a varint.

peekData
void[] peekData(size_t size)

Peeks some data (read it but without changing the buffer's index).

peekVar
T peekVar()

Peeks a varint.

read
T read()

Reads a value with the given endianness.

read
T read()

Reads a value using the system's endianness.

read
T read(size_t length)

Reads an array using the given endianness.

read
T read(size_t size)

Reads an array using the system's endianness.

read
B read()

Reads a varint.

readData
void[] readData(size_t size)

Reads the amount of data requested.

readVar
T readVar()

Reads a varint.

reset
void reset()

Resets the buffer setting the index and its length to 0.

write
void write(T value)

Writes data to buffer using the given endianness.

write
void write(T value)

Writes data to the buffer using the system's endianness.

write
void write(T value)

Writes an array using the given endianness.

write
void write(T value)

Writes an array using the system's endianness.

write
void write(B value)

Writes a varint.

write
void write(T value, size_t index)

Writes data at the given index.

writeData
void writeData(void[] data)

Writes data to the buffer and expands if it is not big enough.

writeVar
void writeVar(T value)

Writes a varint.

Properties

capacity
size_t capacity [@property getter]

Gets the size of the data allocated by the buffer.

data
T[] data [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
data
T[] data [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
data
T[] data [@property setter]

Sets new data and resets the index.

rindex
size_t rindex [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
windex
size_t windex [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

t {
	
	import xbuffer.memory : xalloc;
	
	// a buffer can be garbage collected
	Buffer gc = new Buffer(16);
	
	// or manually allocated
	// alloc is a function provided by the xbuffer.memory module
	Buffer b = xalloc!Buffer(16);
	
	// the memory is realsed with free, which is called by the garbage
	// collector or by the `free` function in the `xbuffer.memory` module
	xfree(b);

Meta