2#include "gaia/config/config.h"
6#include "gaia/cnt/darray.h"
7#include "gaia/cnt/darray_ext.h"
11 enum class serialization_type_id : uint8_t;
14 static constexpr uint32_t SerializationBufferCapacityIncreaseSize = 128U;
16 template <
typename DataContainer>
20 static constexpr uint32_t CapacityIncreaseSize = SerializationBufferCapacityIncreaseSize;
34 GAIA_NODISCARD uint32_t
bytes()
const {
35 return (uint32_t)
m_data.size();
39 GAIA_NODISCARD
bool empty()
const {
44 GAIA_NODISCARD
const auto*
data()
const {
52 if (nextSize <=
bytes())
56 const auto newSize =
bytes() + size;
57 const auto newCapacity = ((newSize / CapacityIncreaseSize) * CapacityIncreaseSize) + CapacityIncreaseSize;
58 m_data.reserve(newCapacity);
80 GAIA_NODISCARD uint32_t
tell()
const {
90 const auto cnt =
m_dataPos + (uint32_t)
sizeof(T);
94 mem = GAIA_FWD(value);
103 void save_raw(
const void* pSrc, uint32_t size, [[maybe_unused]] ser::serialization_type_id
id) {
120 template <
typename T>
124 const auto& cdata = std::as_const(
m_data);
134 void load_raw(
void* pDst, uint32_t size, [[maybe_unused]] ser::serialization_type_id
id) {
140 const auto& cdata = std::as_const(
m_data);
141 memmove(pDst, (
const void*)&cdata[
m_dataPos], size);
Array of elements of type.
Definition darray_ext_impl.h:28
Array with variable size of elements of type.
Definition darray_impl.h:25
Pointer wrapper for writing memory in defined way (not causing undefined behavior)
Definition mem_alloc.h:260
Definition ser_buffer_binary.h:17
void seek(uint32_t pos)
Changes the current position in the buffer.
Definition ser_buffer_binary.h:69
GAIA_NODISCARD uint32_t tell() const
Returns the current position in the buffer.
Definition ser_buffer_binary.h:80
uint32_t m_dataPos
Current position in the buffer.
Definition ser_buffer_binary.h:25
GAIA_NODISCARD uint32_t bytes() const
Returns the number of bytes written in the buffer.
Definition ser_buffer_binary.h:34
GAIA_NODISCARD const auto * data() const
Returns the pointer to the data in the buffer.
Definition ser_buffer_binary.h:44
DataContainer m_data
Buffer holding raw data.
Definition ser_buffer_binary.h:23
void resize(uint32_t size)
Resizes the internal buffer to size bytes.
Definition ser_buffer_binary.h:63
void reserve(uint32_t size)
Makes sure there is enough capacity in our data container to hold another size bytes of data.
Definition ser_buffer_binary.h:50
void save(T &&value)
Writes value to the buffer.
Definition ser_buffer_binary.h:87
void load_raw(void *pDst, uint32_t size, ser::serialization_type_id id)
Loads size bytes of data from the buffer and writes it to the address pDst.
Definition ser_buffer_binary.h:134
void load(T &value)
Loads value from the buffer.
Definition ser_buffer_binary.h:121
void skip(uint32_t size)
Advances size bytes from the current buffer position.
Definition ser_buffer_binary.h:75
GAIA_NODISCARD bool empty() const
Returns true if there is no data written in the buffer.
Definition ser_buffer_binary.h:39
void save_raw(const void *pSrc, uint32_t size, ser::serialization_type_id id)
Writes size bytes of data starting at the address pSrc to the buffer.
Definition ser_buffer_binary.h:103
Definition ser_buffer_binary.h:154
Minimal binary serializer meant to runtime data. It does not offer any versioning,...
Definition ser_buffer_binary.h:153
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9