#ifndef RFL_BSON_READ_HPP_ #define RFL_BSON_READ_HPP_ #include #include #include #include "../Processors.hpp" #include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" namespace rfl { namespace bson { using InputObjectType = typename Reader::InputObjectType; using InputVarType = typename Reader::InputVarType; /// Parses an object from a BSON var. template Result> read(const InputVarType& _obj) { const auto r = Reader(); return Parser>::read(r, _obj); } /// Parses an BSON object using reflection. template auto read(const uint8_t* _bytes, const size_t _size) { Reader::BSONValue value; value.val_.value.v_doc.data_len = static_cast(_size); value.val_.value.v_doc.data = const_cast(_bytes); value.val_.value_type = BSON_TYPE_DOCUMENT; auto doc = InputVarType {&value}; return read(doc); } /// Parses an BSON object using reflection. template auto read(const char* _bytes, const size_t _size) { return read(reinterpret_cast(_bytes), _size); } /// Parses an object from BSON using reflection. template auto read(const std::vector& _bytes) { return read(_bytes.data(), _bytes.size()); } /// Parses an object from a stream. template auto read(std::istream& _stream) { std::istreambuf_iterator begin(_stream), end; auto bytes = std::vector(begin, end); return read(bytes.data(), bytes.size()); } } // namespace bson } // namespace rfl #endif