Added flexbuffers reader and writer as well as first test (but does not pass)

This commit is contained in:
Patrick Urbanke
2023-11-11 23:16:49 +01:00
parent c206699f64
commit 5efa9df16e
70 changed files with 754 additions and 18 deletions
+31
View File
@@ -0,0 +1,31 @@
#ifndef FLEXBUF_WRITE_HPP_
#define FLEXBUF_WRITE_HPP_
#include <flatbuffers/flexbuffers.h>
#include <cstddef>
#include <sstream>
#include <vector>
#include "rfl/flexbuf/Parser.hpp"
namespace rfl {
namespace flexbuf {
/// Writes an object to flexbuf.
template <class T>
std::vector<unsigned char> write(const T& _obj) {
auto w = Writer();
const auto flexbuf_obj = Parser<T>::write(w, _obj);
flexbuffers::Builder fbb;
flexbuf_obj->insert(std::nullopt, &fbb);
fbb.Finish();
const auto vec = fbb.GetBuffer();
const auto data = reinterpret_cast<const unsigned char*>(vec.data());
return std::vector<unsigned char>(data, data + vec.size());
}
} // namespace flexbuf
} // namespace rfl
#endif