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>
21 static constexpr uint32_t CapacityIncreaseSize = SerializationBufferCapacityIncreaseSize;
35 GAIA_NODISCARD uint32_t
bytes()
const {
36 return (uint32_t)
m_data.size();
40 GAIA_NODISCARD
bool empty()
const {
45 GAIA_NODISCARD
const auto*
data()
const {
53 if (nextSize <=
bytes())
57 const auto newSize =
bytes() + size;
58 const auto newCapacity = ((newSize / CapacityIncreaseSize) * CapacityIncreaseSize) + CapacityIncreaseSize;
59 m_data.reserve(newCapacity);
81 GAIA_NODISCARD uint32_t
tell()
const {
91 const auto cnt =
m_dataPos + (uint32_t)
sizeof(T);
95 mem = GAIA_FWD(value);
104 void save_raw(
const void* pSrc, uint32_t size, [[maybe_unused]] ser::serialization_type_id
id) {
121 template <
typename T>
125 const auto& cdata = std::as_const(
m_data);
135 void load_raw(
void* pDst, uint32_t size, [[maybe_unused]] ser::serialization_type_id
id) {
141 const auto& cdata = std::as_const(
m_data);
142 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
In-memory binary read/write stream used by compile-time and runtime serializers.
Definition ser_buffer_binary.h:18
void seek(uint32_t pos)
Changes the current position in the buffer.
Definition ser_buffer_binary.h:70
GAIA_NODISCARD uint32_t tell() const
Returns the current position in the buffer.
Definition ser_buffer_binary.h:81
uint32_t m_dataPos
Current position in the buffer.
Definition ser_buffer_binary.h:26
GAIA_NODISCARD uint32_t bytes() const
Returns the number of bytes written in the buffer.
Definition ser_buffer_binary.h:35
GAIA_NODISCARD const auto * data() const
Returns the pointer to the data in the buffer.
Definition ser_buffer_binary.h:45
DataContainer m_data
Buffer holding raw data.
Definition ser_buffer_binary.h:24
void resize(uint32_t size)
Resizes the internal buffer to size bytes.
Definition ser_buffer_binary.h:64
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:51
void save(T &&value)
Writes value to the buffer.
Definition ser_buffer_binary.h:88
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:135
void load(T &value)
Loads value from the buffer.
Definition ser_buffer_binary.h:122
void skip(uint32_t size)
Advances size bytes from the current buffer position.
Definition ser_buffer_binary.h:76
GAIA_NODISCARD bool empty() const
Returns true if there is no data written in the buffer.
Definition ser_buffer_binary.h:40
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:104
Same API as ser_buffer_binary, but backed by fully dynamic storage.
Definition ser_buffer_binary.h:157
Minimal in-memory binary serializer. It stores raw bytes only (no schema, versioning,...
Definition ser_buffer_binary.h:155
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9