diff --git a/src/data/StructMapper.hpp b/src/data/StructMapper.hpp new file mode 100644 index 00000000..1c92f882 --- /dev/null +++ b/src/data/StructMapper.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include + +#include "typedefs.hpp" + +namespace data { + enum class FieldType { + I8, I16, I32, I64, F32, F64 + }; + + struct Field { + FieldType type; + std::string name; + int offset; + }; + + class StructMapping { + std::vector fields; + std::unordered_map indices; + public: + const Field* getField(const std::string& name) const { + auto found = indices.find(name); + if (found == indices.end()) { + return nullptr; + } + return &fields.at(found->second); + } + }; + + class StructAccess { + const StructMapping& mapping; + uint8_t* buffer; + public: + StructAccess(const StructMapping& mapping, uint8_t* buffer) + : mapping(mapping), buffer(buffer) { + } + }; +}