/buffer

a C++11 class to maintain binary data

Primary LanguageC++

Buffer

A C++11 class to maintain binary data. I was always writing a class like this for each project I did, so I thought I would do it once and for all. The code is based on this implementation.

A buffer object maintains a pointer, a size and a capacity.

buffer b(43);

b.size(); // 43
b.capacity(); // 43
b.data(); // pointer to the data

Use a buffer_reader to read from a buffer.

buffer b("first line\nsecond line");
buffer_reader reader(b);

std::string line;
reader.read(line); // will write "first line" into string
reader.read(line); // will write "second line" into string

Use a buffer_writer to write to the buffer.

buffer b;
buffer_writer writer(b);

writer.write({1, 2, 3});

Check the header files and the unit tests to se the available methods.