Skip to content

Commit

Permalink
Implemented the read function
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Jan 21, 2024
1 parent d5d096d commit c1c2f36
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/rfl/cbor/read.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RFL_CBOR_READ_HPP_
#define RFL_CBOR_READ_HPP_

#include <bson/bson.h>
#include <cbor.h>

#include <istream>
#include <string>
Expand All @@ -23,14 +23,14 @@ auto read(const InputVarType& _obj) {
return Parser<T>::read(r, _obj);
}

/// Parses an object from flexbuf using reflection.
/// Parses an object from CBOR using reflection.
template <class T>
Result<internal::wrap_in_rfl_array_t<T>> read(char* _bytes,
Result<internal::wrap_in_rfl_array_t<T>> read(const char* _bytes,
const size_t _size) {
Reader::CBORValue value;
value.val_.value.v_doc.data_len = static_cast<uint32_t>(_size);
value.val_.value.v_doc.data = reinterpret_cast<uint8_t*>(_bytes);
value.val_.value_type = CBOR_TYPE_DOCUMENT;
CborParser parser;
CborValue value;
cbor_parser_init(reinterpret_cast<const uint8_t*>(_bytes), _size, 0, &parser,
&value);
auto doc = InputVarType{&value};
auto result = read<T>(doc);
return result;
Expand Down

0 comments on commit c1c2f36

Please sign in to comment.