-
Notifications
You must be signed in to change notification settings - Fork 5.5k
add a helper class for runtime-derived uint32 #16398
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 5 commits
0a34c9b
f553f65
eed421c
682f4c1
a1cffc4
0d86df8
9f39b77
9fd4ead
0610dcf
4e22777
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 |
|---|---|---|
|
|
@@ -11,6 +11,32 @@ | |
| namespace Envoy { | ||
| namespace Runtime { | ||
|
|
||
| // Helper class for runtime-derived uint32. | ||
| class UInt32 : Logger::Loggable<Logger::Id::runtime> { | ||
| public: | ||
| UInt32(const envoy::config::core::v3::RuntimeUInt32& uint32_proto, Runtime::Loader& runtime) | ||
| : runtime_key_(uint32_proto.runtime_key()), default_value_(uint32_proto.default_value()), | ||
| runtime_(runtime) {} | ||
|
|
||
| const std::string& runtimeKey() const { return runtime_key_; } | ||
|
|
||
| uint32_t value() const { | ||
| uint64_t raw_value = runtime_.snapshot().getInteger(runtime_key_, default_value_); | ||
| if (raw_value > std::numeric_limits<uint32_t>::max()) { | ||
| ENVOY_LOG_EVERY_POW_2(warn, | ||
| "value:{} of {} is larger than uint32 max, return default instead", | ||
|
Member
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. Sorry one more-- can you mention in the message that it's a parsed runtime value and swap "return" for "returning". It'll be good to go after that.
Contributor
Author
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. Sure. |
||
| raw_value, runtime_key_); | ||
| return default_value_; | ||
| } | ||
| return static_cast<uint32_t>(raw_value); | ||
| } | ||
|
|
||
| private: | ||
| const std::string runtime_key_; | ||
| const uint32_t default_value_; | ||
| Runtime::Loader& runtime_; | ||
| }; | ||
|
|
||
| // Helper class for runtime-derived boolean feature flags. | ||
| class FeatureFlag { | ||
| public: | ||
|
|
||
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.
Mind adding a unit test for this?
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.
done.