Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
ser_binary.h
1#pragma once
2#include "gaia/config/config.h"
3
4#include "gaia/mem/mem_alloc.h"
5#include "gaia/ser/ser_buffer_binary.h"
6#include "gaia/ser/ser_rt.h"
7
8namespace gaia {
9 namespace ecs {
12
14 void align(uint32_t size, ser::serialization_type_id id) {
15 const auto pos = m_buffer.tell();
16 const auto posAligned = mem::align(pos, ser::serialization_type_size(id, size));
17 const auto offset = posAligned - pos;
18 m_buffer.reserve(offset + size);
19 m_buffer.skip(offset);
20 }
21
22 public:
23 void save_raw(const void* src, uint32_t size, ser::serialization_type_id id) override {
24 align(size, id);
25 m_buffer.save_raw((const char*)src, size, id);
26 }
27
28 void load_raw(void* src, uint32_t size, ser::serialization_type_id id) override {
29 align(size, id);
30 m_buffer.load_raw((char*)src, size, id);
31 }
32
33 const char* data() const override {
34 return (const char*)m_buffer.data();
35 }
36
37 void reset() override {
38 m_buffer.reset();
39 }
40
41 uint32_t tell() const override {
42 return m_buffer.tell();
43 }
44
45 uint32_t bytes() const override {
46 return m_buffer.bytes();
47 }
48
49 void seek(uint32_t pos) override {
50 m_buffer.seek(pos);
51 }
52 };
53 } // namespace ecs
54} // namespace gaia
Definition ser_binary.h:10
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
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
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 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 skip(uint32_t size)
Advances size bytes from the current buffer position.
Definition ser_buffer_binary.h:75
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
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
Definition ser_rt.h:13