-
Notifications
You must be signed in to change notification settings - Fork 1
FEAT: Add hasher parsing support #370
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 3 commits
a9659c3
60d8f2a
e07a5a2
8240ca6
e33eb2a
7e4c756
c17d264
c2ca499
a576134
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 |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| #include <memory> | ||
|
|
||
| #include "device/host.hpp" | ||
| #include "identifiable_parser.hpp" | ||
| #include "parser/parse_utils.hpp" | ||
| #include "utils/hasher.hpp" | ||
|
|
||
| namespace sim { | ||
|
|
||
| template <> | ||
| std::shared_ptr<Host> Parser<Host>::parse_object( | ||
| const YAML::Node& key_node, const YAML::Node& value_node) { | ||
| (void)value_node; | ||
| return std::make_shared<Host>(key_node.as<Id>()); | ||
| std::shared_ptr<Host> Parser<Host>::parse_object(const YAML::Node& key_node, | ||
| const YAML::Node& value_node) { | ||
| std::unique_ptr<IHasher> hasher = nullptr; | ||
| if (value_node["hasher"]) { | ||
| hasher = parse_hasher(value_node); | ||
| } | ||
| return std::make_shared<Host>(key_node.as<Id>(), std::move(hasher)); | ||
| } | ||
|
|
||
| } // namespace sim | ||
| } // namespace sim | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,12 @@ | |||||||
|
|
||||||||
| #include <spdlog/fmt/fmt.h> | ||||||||
|
|
||||||||
| #include <memory> | ||||||||
| #include <stdexcept> | ||||||||
|
|
||||||||
| #include "logger/logger.hpp" | ||||||||
| #include "utils/hasher.hpp" | ||||||||
|
|
||||||||
| static std::pair<uint32_t, std::string> parse_value_unit( | ||||||||
| const std::string &value_with_unit) { | ||||||||
| const size_t unit_pos = value_with_unit.find_first_not_of("0123456789"); | ||||||||
|
|
@@ -52,4 +56,20 @@ uint32_t parse_with_default( | |||||||
| return default_value; | ||||||||
| } | ||||||||
| return value_parser(node[field_name].as<std::string>()); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| std::unique_ptr<sim::IHasher> parse_hasher(const YAML::Node &node) { | ||||||||
| const std::string hasher_field_name = "hasher"; | ||||||||
| const std::string hasher_value = node[hasher_field_name].as<std::string>(); | ||||||||
|
AntoxaBarin marked this conversation as resolved.
Outdated
|
||||||||
| if (hasher_value == "random") { | ||||||||
| return std::make_unique<sim::RandomHasher>(); | ||||||||
| } | ||||||||
| if (hasher_value == "base") { | ||||||||
| return std::make_unique<sim::BaseHasher>(); | ||||||||
| } | ||||||||
| if (hasher_value == "symmetric") { | ||||||||
| return std::make_unique<sim::SymmetricHasher>(); | ||||||||
| } | ||||||||
| LOG_WARN(fmt::format("Unknown hasher type: {}", hasher_value)); | ||||||||
| return std::make_unique<sim::BaseHasher>(); | ||||||||
|
Collaborator
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. I think its better to throw error here:
Suggested change
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. Do we really want to force user to specify hasher? I think it would be more convenient to just set some default value if hasher is not specified and write some warining log, as suggested above
Collaborator
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. We have 'parse_with_default', so yes |
||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.