-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add function manager for register and run function by function name #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b742234
dbee1f3
5752827
07e10f7
48051b8
a02bac3
ddb872b
5027444
292ed6a
5146981
32ac459
6190671
2fd81ec
ba12ceb
08db6ec
9757935
2034f6b
2df4e7f
059ffc1
92c1e17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #ifndef SPIDER_MSGPACK_HPP | ||
| #define SPIDER_MSGPACK_HPP | ||
|
|
||
| // clang-format off | ||
| // IWYU pragma: begin_exports | ||
|
|
||
| #include <msgpack.hpp> | ||
|
|
||
| #include <msgpack/iterator.hpp> | ||
| #include <msgpack/null_visitor.hpp> | ||
| #include <msgpack/object.hpp> | ||
| #include <msgpack/pack.hpp> | ||
| #include <msgpack/parse.hpp> | ||
| #include <msgpack/sbuffer.hpp> | ||
| #include <msgpack/type.hpp> | ||
| #include <msgpack/unpack.hpp> | ||
| #include <msgpack/version.hpp> | ||
| #include <msgpack/vrefbuffer.hpp> | ||
| #include <msgpack/x3_parse.hpp> | ||
| #include <msgpack/x3_unpack.hpp> | ||
| #include <msgpack/zone.hpp> | ||
|
|
||
| #include <msgpack/adaptor/define_decl.hpp> | ||
| #include <msgpack/v3/adaptor/adaptor_base.hpp> | ||
| #include <msgpack/v3/object_decl.hpp> | ||
| #include <msgpack/v3/object_fwd.hpp> | ||
| #include <msgpack/v3/object_fwd_decl.hpp> | ||
| #include <msgpack/v3/pack_decl.hpp> | ||
| #include <msgpack/v3/sbuffer_decl.hpp> | ||
| #include <msgpack/v3/unpack.hpp> | ||
|
|
||
| // IWYU pragma: end_exports | ||
| // clang-format on | ||
|
|
||
| #endif // SPIDER_MSGPACK_HPP |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||
| #ifndef SPIDER_CORE_SERIALIZER_HPP | ||||||||||||||||||
| #define SPIDER_CORE_SERIALIZER_HPP | ||||||||||||||||||
|
|
||||||||||||||||||
| #include <boost/uuid/uuid.hpp> | ||||||||||||||||||
| #include <cstdint> | ||||||||||||||||||
| #include <cstring> | ||||||||||||||||||
|
|
||||||||||||||||||
| #include "MsgPack.hpp" // IWYU pragma: keep | ||||||||||||||||||
|
|
||||||||||||||||||
| template <> | ||||||||||||||||||
| struct msgpack::adaptor::convert<boost::uuids::uuid> { | ||||||||||||||||||
| auto operator()(msgpack::object const& object, boost::uuids::uuid& id) const | ||||||||||||||||||
| -> msgpack::object const& { | ||||||||||||||||||
|
Comment on lines
+12
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider returning void instead of const reference. Returning a const reference to a parameter can lead to dangling references if the parameter's lifetime ends. Since the object isn't modified, consider changing the return type to void. - auto operator()(msgpack::object const& object, boost::uuids::uuid& id) const
- -> msgpack::object const& {
+ void operator()(msgpack::object const& object, boost::uuids::uuid& id) const {📝 Committable suggestion
Suggested change
|
||||||||||||||||||
| // NOLINTBEGIN(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-return-const-ref-from-parameter) | ||||||||||||||||||
| if (object.type != type::BIN) { | ||||||||||||||||||
| throw type_error(); | ||||||||||||||||||
| } | ||||||||||||||||||
| if (object.via.bin.size != boost::uuids::uuid::static_size()) { | ||||||||||||||||||
| throw type_error(); | ||||||||||||||||||
| } | ||||||||||||||||||
| std::uint8_t data[boost::uuids::uuid::static_size()]; | ||||||||||||||||||
| std::memcpy(data, object.via.bin.ptr, boost::uuids::uuid::static_size()); | ||||||||||||||||||
| id = boost::uuids::uuid{data}; | ||||||||||||||||||
|
Comment on lines
+21
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using std::array for safer memory operations. The current implementation uses C-style arrays and memcpy. Consider using std::array for better type safety and std::copy_n for more explicit bounds checking. - std::uint8_t data[boost::uuids::uuid::static_size()];
- std::memcpy(data, object.via.bin.ptr, boost::uuids::uuid::static_size());
- id = boost::uuids::uuid{data};
+ std::array<std::uint8_t, boost::uuids::uuid::static_size()> data;
+ std::copy_n(static_cast<const std::uint8_t*>(object.via.bin.ptr),
+ boost::uuids::uuid::static_size(),
+ data.begin());
+ id = boost::uuids::uuid{data.data()};📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| return object; | ||||||||||||||||||
| // NOLINTEND(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-return-const-ref-from-parameter) | ||||||||||||||||||
| } | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| template <> | ||||||||||||||||||
| struct msgpack::adaptor::pack<boost::uuids::uuid> { | ||||||||||||||||||
| template <class Stream> | ||||||||||||||||||
| auto operator()(msgpack::packer<Stream>& packer, boost::uuids::uuid const& id) const | ||||||||||||||||||
| -> msgpack::packer<Stream>& { | ||||||||||||||||||
| packer.pack_bin(id.size()); | ||||||||||||||||||
| // NOLINTBEGIN(cppcoreguidelines-pro-type-cstyle-cast) | ||||||||||||||||||
| packer.pack_bin_body((char const*)id.data(), id.size()); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace C-style cast with reinterpret_cast. Using C-style casts can hide dangerous conversions. Use explicit C++ cast operators instead. - packer.pack_bin_body((char const*)id.data(), id.size());
+ packer.pack_bin_body(reinterpret_cast<char const*>(id.data()), id.size());📝 Committable suggestion
Suggested change
|
||||||||||||||||||
| // NOLINTEND(cppcoreguidelines-pro-type-cstyle-cast) | ||||||||||||||||||
| return packer; | ||||||||||||||||||
| } | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| #endif // SPIDER_CORE_SERIALIZER_HPP | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling consistency with other dependencies
The error handling for msgpack-cxx should follow the same pattern as other dependencies in the file, particularly for static/shared library scenarios.
Apply this diff to improve the error handling:
# Find and setup msgpack if(SPIDER_USE_STATIC_LIBS) set(msgpack-cxx_USE_STATIC_LIBS ON) endif() find_package(msgpack-cxx 7.0.0 REQUIRED) if(msgpack-cxx_FOUND) message(STATUS "Found msgpack-cxx ${msgpack-cxx_VERSION}") else() - message(FATAL_ERROR "Could not find msgpack-cxx") + if(SPIDER_USE_STATIC_LIBS) + message(FATAL_ERROR "Could not find static libraries for msgpack-cxx") + else() + message(FATAL_ERROR "Could not find ${SPIDER_LIBS_STRING} libraries for msgpack-cxx") + endif() endif()