#pragma once #include "../types.hpp" #include "../utils.hpp" #include #include namespace sibs { /** * Endian independent serializer */ class SafeSerializer { DISABLE_COPY(SafeSerializer); public: SafeSerializer(){} template void add(const T &data) { usize offset = buffer.size(); buffer.resize(buffer.size() + sizeof(data)); memcpy(&buffer[offset], &data, sizeof(data)); } void add(const u8 *data, usize size) { if(size > 0) { usize offset = buffer.size(); buffer.resize(buffer.size() + size); memcpy(&buffer[offset], data, size); } } std::vector& getBuffer() { return buffer; } private: std::vector buffer; }; }