Skip to content

Commit 70950a3

Browse files
Optimized read(...)
1 parent f9137eb commit 70950a3

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

include/rfl/ubjson/read.hpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,18 @@ using InputVarType = typename Reader::InputVarType;
1919

2020
/// Parses an object from UBJSON using reflection.
2121
template <class T, class... Ps>
22-
Result<internal::wrap_in_rfl_array_t<T>> read(const char* _bytes,
23-
const size_t _size) {
24-
auto buffer =
25-
std::vector<uint8_t>(std::bit_cast<const uint8_t*>(_bytes),
26-
std::bit_cast<const uint8_t*>(_bytes) + _size);
27-
auto val = jsoncons::ubjson::decode_ubjson<jsoncons::json>(buffer);
22+
Result<internal::wrap_in_rfl_array_t<T>> read(const std::vector<char>& _bytes) {
23+
auto val = jsoncons::ubjson::decode_ubjson<jsoncons::json>(_bytes);
2824
auto r = Reader();
29-
auto result = Parser<T, Processors<Ps...>>::read(r, InputVarType{&val});
30-
return result;
31-
}
32-
33-
/// Parses an object from UBJSON using reflection.
34-
template <class T, class... Ps>
35-
auto read(const std::vector<char>& _bytes) {
36-
return read<T, Ps...>(_bytes.data(), _bytes.size());
25+
return Parser<T, Processors<Ps...>>::read(r, InputVarType{&val});
3726
}
3827

3928
/// Parses an object from a stream.
4029
template <class T, class... Ps>
41-
auto read(std::istream& _stream) {
42-
std::istreambuf_iterator<char> begin(_stream), end;
43-
auto bytes = std::vector<char>(begin, end);
44-
return read<T, Ps...>(bytes.data(), bytes.size());
30+
Result<internal::wrap_in_rfl_array_t<T>> read(std::istream& _stream) {
31+
auto val = jsoncons::ubjson::decode_ubjson<jsoncons::json>(_stream);
32+
auto r = Reader();
33+
return Parser<T, Processors<Ps...>>::read(r, InputVarType{&val});
4534
}
4635

4736
} // namespace rfl::ubjson

0 commit comments

Comments
 (0)