#ifndef FLEXBUF_READ_HPP_ #define FLEXBUF_READ_HPP_ #include #include #include #include "../Processors.hpp" #include "../Result.hpp" #include "Parser.hpp" namespace rfl { namespace flexbuf { using InputVarType = typename Reader::InputVarType; /// Parses an object from flexbuf var. template auto read(const InputVarType& _obj) { const auto r = Reader(); return Parser>::read(r, _obj); } /// Parses an object from flexbuf using reflection. template auto read(const char* _bytes, const size_t _size) { const InputVarType root = flexbuffers::GetRoot(reinterpret_cast(_bytes), _size); return read(root); } /// Parses an object from flexbuf using reflection. template auto read(const std::vector& _bytes) { return read(_bytes.data(), _bytes.size()); } /// Parses an object directly from a stream. template auto read(std::istream& _stream) { std::istreambuf_iterator begin(_stream), end; const auto bytes = std::vector(begin, end); return read(bytes.data(), bytes.size()); } } // namespace flexbuf } // namespace rfl #endif