Files
MushMachine/framework/s6zer/src/mm/s6zer/serialize.hpp
Green Sky f27300a8fa add new serializer based on bitpacking
it has the important stuff, but still misses conviniences like buffers
and optimizations like varints.
only works for little endian but theoretically only needs endian
detection to be able to support bigendian
2022-12-07 00:35:25 +01:00

34 lines
770 B
C++

#pragma once
#include "./stream.hpp"
namespace MM::s6zer {
// serialize macros
// TODO: make use of ADL, like nlohmann::json does.
/*
defines mm_serialize functions for you.
a "stream" object is in scope (StreamWriter/StreamReader),
as well as the object of Type called "data".
eg:
MM_DEFINE_SERIALIZE(Test1,
MM_S6ZER_BAIL(stream.serializeBits(data.seq, 16))
MM_S6ZER_BAIL(stream.serializeBits(data.data1, 8))
)
*/
// TODO: refine, so we dont have to do MM_S6ZER_BAIL() everytime
#define MM_DEFINE_SERIALIZE(Type, ...) \
inline bool mm_serialize(MM::s6zer::StreamWriter& stream, const Type& data) { \
__VA_ARGS__ \
return true; \
} \
inline bool mm_serialize(MM::s6zer::StreamReader& stream, Type& data) { \
__VA_ARGS__ \
return true; \
}
} // MM::s6zer