mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 18:56:19 +08:00
Move some heavy templates into cpp (#204)
This commit is contained in:
@@ -27,33 +27,12 @@ struct Reader {
|
||||
});
|
||||
|
||||
rfl::Result<InputVarType> get_field_from_array(
|
||||
const size_t _idx, const InputArrayType _arr) const noexcept {
|
||||
if (_idx >= _arr.size) {
|
||||
return rfl::Error("Index " + std::to_string(_idx) + " of of bounds.");
|
||||
}
|
||||
return _arr.ptr[_idx];
|
||||
}
|
||||
const size_t _idx, const InputArrayType _arr) const noexcept;
|
||||
|
||||
rfl::Result<InputVarType> get_field_from_object(
|
||||
const std::string& _name, const InputObjectType& _obj) const noexcept {
|
||||
for (uint32_t i = 0; i < _obj.size; ++i) {
|
||||
const auto& key = _obj.ptr[i].key;
|
||||
if (key.type != MSGPACK_OBJECT_STR) {
|
||||
return Error("Key in element " + std::to_string(i) +
|
||||
" was not a string.");
|
||||
}
|
||||
const auto current_name =
|
||||
std::string_view(key.via.str.ptr, key.via.str.size);
|
||||
if (_name == current_name) {
|
||||
return _obj.ptr[i].val;
|
||||
}
|
||||
}
|
||||
return Error("No field named '" + _name + "' was found.");
|
||||
}
|
||||
const std::string& _name, const InputObjectType& _obj) const noexcept ;
|
||||
|
||||
bool is_empty(const InputVarType& _var) const noexcept {
|
||||
return _var.type == MSGPACK_OBJECT_NIL;
|
||||
}
|
||||
bool is_empty(const InputVarType& _var) const noexcept;
|
||||
|
||||
template <class T>
|
||||
rfl::Result<T> to_basic_type(const InputVarType& _var) const noexcept {
|
||||
@@ -96,20 +75,10 @@ struct Reader {
|
||||
}
|
||||
|
||||
rfl::Result<InputArrayType> to_array(
|
||||
const InputVarType& _var) const noexcept {
|
||||
if (_var.type != MSGPACK_OBJECT_ARRAY) {
|
||||
return Error("Could not cast to an array.");
|
||||
}
|
||||
return _var.via.array;
|
||||
}
|
||||
const InputVarType& _var) const noexcept;
|
||||
|
||||
rfl::Result<InputObjectType> to_object(
|
||||
const InputVarType& _var) const noexcept {
|
||||
if (_var.type != MSGPACK_OBJECT_MAP) {
|
||||
return Error("Could not cast to a map.");
|
||||
}
|
||||
return _var.via.map;
|
||||
}
|
||||
const InputVarType& _var) const noexcept;
|
||||
|
||||
template <class ArrayReader>
|
||||
std::optional<Error> read_array(const ArrayReader& _array_reader,
|
||||
@@ -153,4 +122,4 @@ struct Reader {
|
||||
} // namespace msgpack
|
||||
} // namespace rfl
|
||||
|
||||
#endif // JSON_PARSER_HPP_
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user