-
Notifications
You must be signed in to change notification settings - Fork 5.3k
matcher: add support for new any matcher mechanism #19143
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
a56a864
86db280
9d59dde
e264d43
435cb54
c06f3f1
c8a610f
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 |
|---|---|---|
|
|
@@ -61,6 +61,22 @@ static inline MaybeMatchResult evaluateMatch(MatchTree<DataType>& match_tree, | |
|
|
||
| template <class DataType> using FieldMatcherFactoryCb = std::function<FieldMatcherPtr<DataType>()>; | ||
|
|
||
| /** | ||
| * A matcher that will always resolve to associated on_no_match. This is used when | ||
| * the matcher is configured without a matcher, allowing for a tree that always resolves | ||
| * to a specific OnMatch. | ||
| */ | ||
| template <class DataType> class AnyMatcher : public MatchTree<DataType> { | ||
| public: | ||
| explicit AnyMatcher(absl::optional<OnMatch<DataType>> on_no_match) | ||
| : on_no_match_(std::move(on_no_match)) {} | ||
|
|
||
| typename MatchTree<DataType>::MatchResult match(const DataType&) override { | ||
| return {MatchState::MatchComplete, on_no_match_}; | ||
|
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. I'm not an expert here, but should the 2nd param (
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. I think in other use cases this always does a copy, since the Action object is generally small (lambda + pointer). We could probably change this around but would be a bigger refactor I think |
||
| } | ||
| const absl::optional<OnMatch<DataType>> on_no_match_; | ||
| }; | ||
|
|
||
| /** | ||
| * Recursively constructs a MatchTree from a protobuf configuration. | ||
| * @param DataType the type used as a source for DataInputs | ||
|
|
@@ -83,8 +99,7 @@ class MatchTreeFactory : public OnMatchFactory<DataType> { | |
| case MatcherType::kMatcherList: | ||
| return createListMatcher(config); | ||
| case MatcherType::MATCHER_TYPE_NOT_SET: | ||
| IS_ENVOY_BUG("match fail"); | ||
| return nullptr; | ||
| return createAnyMatcher(config); | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
@@ -100,6 +115,15 @@ class MatchTreeFactory : public OnMatchFactory<DataType> { | |
| } | ||
|
|
||
| private: | ||
| template <class MatcherType> | ||
| MatchTreeFactoryCb<DataType> createAnyMatcher(const MatcherType& config) { | ||
| auto on_no_match = createOnMatch(config.on_no_match()); | ||
|
|
||
| return [on_no_match]() { | ||
| return std::make_unique<AnyMatcher<DataType>>( | ||
| on_no_match ? absl::make_optional((*on_no_match)()) : absl::nullopt); | ||
| }; | ||
| } | ||
| template <class MatcherType> | ||
| MatchTreeFactoryCb<DataType> createListMatcher(const MatcherType& config) { | ||
| std::vector<std::pair<FieldMatcherFactoryCb<DataType>, OnMatchFactoryCb<DataType>>> | ||
|
|
||
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.
Please add some comments.