4 #include "ArraySegment.hpp"
5 #include "Platform.hpp"
9 #define BUFFER_SIZE 1024
14 byte* buffer =
nullptr;
20 buffer =
new byte[BUFFER_SIZE];
21 bufferSize = BUFFER_SIZE;
26 buffer =
new byte[
size];
36 inline void reset() { position = 0; }
47 ensureCapacity(position +
size);
49 std::copy((
char*)&value, (
char*)&value +
size, buffer + position);
59 explicit operator byte*() {
return toArray(); }
71 inline int size()
const {
return position; }
74 inline void ensureCapacity(
int value) {
75 if (position > bufferSize) {
89 if (offset < 0 || count < 0) {
90 throw std::invalid_argument(
"offset or count is less than 0");
95 ensureCapacity(position + count);
96 std::copy(array + offset, array + offset + count, buffer + position);
105 write((
short)value.length());
106 writeBytes((
byte*)value.c_str(), 0, (
int)value.length());
std::shared_ptr< ArraySegment< byte > > toArraySegment()
Get the buffer.
Definition: NetworkWriter.hpp:65
void writeBytes(byte *array, int offset, int count)
Write a byte array to the buffer.
Definition: NetworkWriter.hpp:88
byte * toArray()
Get the buffer.
Definition: NetworkWriter.hpp:57
void writeString(const std::string &value)
Write a string to the buffer.
Definition: NetworkWriter.hpp:104
void reset()
Reset the position to 0.
Definition: NetworkWriter.hpp:36
static void resizeArray(T *&array, int size, int newSize)
Resize an array.
Definition: Array.hpp:15
void write(T value)
Write a value to the buffer.
Definition: NetworkWriter.hpp:44
Definition: NetworkWriter.hpp:12
int size() const
Get the size of the buffer.
Definition: NetworkWriter.hpp:71
static T * copyArray(T *array, int size)
Copy an array.
Definition: Array.hpp:33
Definition: ArraySegment.hpp:9