17#include <initializer_list>
74 Buffer(
std::initializer_list<
unsigned char> bytes) noexcept;
123 [[nodiscard]]
size_t size() const noexcept {
return mSize; }
131 [[nodiscard]]
bool empty() const noexcept {
return mSize == 0; }
135 [[nodiscard]]
bool owns() const noexcept {
return mOwns; }
139 [[nodiscard]]
bool valid() const noexcept {
return mBuffer !=
nullptr; }
193 explicit operator bool() const noexcept;
195 operator const
unsigned char*() const noexcept;
196 operator const
char*() const noexcept;
197 operator
unsigned char*() noexcept;
198 operator
char*() noexcept;
225 void write(const
char* buf,
size_t length) noexcept;
231 [[nodiscard]] auto
reference(
size_t start = 0,
size_t length =
std::numeric_limits<
size_t>::max()) const noexcept ->
Buffer;
248 if(
mSize != other.mSize) {
259 inline Buffer::operator bool() const noexcept {
return valid(); }
261 inline Buffer::operator
const unsigned char*()
const noexcept {
return reinterpret_cast<const unsigned char*
>(
data()); }
262 inline Buffer::operator
const char*()
const noexcept {
return reinterpret_cast<const char*
>(
data()); }
263 inline Buffer::operator
unsigned char*()
noexcept {
return reinterpret_cast<unsigned char*
>(
data()); }
264 inline Buffer::operator
char*()
noexcept {
return reinterpret_cast<char*
>(
data()); }
270 using Buffer::Buffer;
293 return hash(buffer.
begin(), buffer.
end());
297template<>
struct std::hash<
CeresEngine::CopyableBuffer> : std::hash<CeresEngine::Buffer> {};
Represents a secure buffer i.e.
Definition Buffer.hpp:28
bool valid() const noexcept
Checks if the buffer is valid.
Definition Buffer.hpp:139
ConstIterator cend() const noexcept
Gets a iterator that points to the end of the buffer.
Definition Buffer.hpp:164
const Byte * data() const noexcept
Gets a pointer to the raws buffer data.
Definition Buffer.hpp:111
Iterator end() noexcept
Gets a iterator that points to the end of the buffer.
Definition Buffer.hpp:148
size_t capacity() const noexcept
Gets the buffer capacity.
Definition Buffer.hpp:127
Buffer copy() const noexcept
Creates a explicit buffer copy.
Iterator begin() noexcept
Gets a iterator that points to the begining of the buffer.
Definition Buffer.hpp:144
std::string hexdump() const noexcept
Creates a hexdump representation.
Byte * data() noexcept
Gets a pointer to the raws buffer data.
Definition Buffer.hpp:107
auto reference(size_t start=0, size_t length=std::numeric_limits< size_t >::max()) const noexcept -> Buffer
Creates a buffer reference.
bool mOwns
A flag that indicates whether the buffer is owned or not.
Definition Buffer.hpp:47
void write(const char *buf, size_t length) noexcept
Writes buf to the end of the buffer.
bool operator!=(const Buffer &other) const noexcept
Compares a buffer for inequality If either buffer contain the same address and size,...
Definition Buffer.hpp:255
size_t mCapacity
The buffer capacity.
Definition Buffer.hpp:44
ConstIterator begin() const noexcept
Gets a iterator that points to the beginning of the buffer.
Definition Buffer.hpp:152
bool operator==(const Buffer &other) const noexcept
Compares a buffer for equality If either buffer contain the same address and size,...
Definition Buffer.hpp:244
void reserve(size_t newCapacity) noexcept
Reservers at least newCapacity bytes in the buffer.
const Byte * buffer() const noexcept
Gets a pointer to the raws buffer data.
Definition Buffer.hpp:119
Byte & operator[](size_t offset) noexcept
Accesses a buffer element by its offset.
Definition Buffer.hpp:256
Byte * mBuffer
The buffer pointer.
Definition Buffer.hpp:38
void append(const Buffer &buffer) noexcept
Appends a buffer to the end of this buffer.
size_t size() const noexcept
Gets the number of bytes currently allocated in the buffer.
Definition Buffer.hpp:123
void resize(size_t newSize) noexcept
Resizes the buffer to be able to store up-to "newSize" bytes.
bool owns() const noexcept
Checks if the buffer is currently owned.
Definition Buffer.hpp:135
std::string hexstring() const noexcept
Creates a hexdump representation.
ConstIterator end() const noexcept
Gets a iterator that points to the end of the buffer.
Definition Buffer.hpp:156
Buffer() noexcept
Creates a new empty buffer.
ConstIterator cbegin() const noexcept
Gets a iterator that points to the beginning of the buffer.
Definition Buffer.hpp:160
size_t mSize
The buffer size.
Definition Buffer.hpp:41
bool empty() const noexcept
Checks if the buffer is currently empty (i.e.
Definition Buffer.hpp:131
Byte * buffer() noexcept
Gets a pointer to the raws buffer data.
Definition Buffer.hpp:115
void own() noexcept
Transforms a unowned buffer into a owned buffer.
Definition Buffer.hpp:268
CopyableBuffer() noexcept
Definition Application.hpp:19
Byte
Definition DataTypes.hpp:40
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25