Skip to content

Commit

Permalink
mobile: make Envoy::DirectResponseTesting::MatchMode an enum class (
Browse files Browse the repository at this point in the history
envoyproxy#26037)

They seem to have a number of advantages over "plain" enums according to
https://stackoverflow.com/a/18335862, and this will allow them to be
imported properly into Swift.

Also change case names to be PascalCase to conform to the style guide:
https://github.com/envoyproxy/envoy/blob/main/STYLE.md

Similar to envoyproxy#26036

Signed-off-by: JP Simard <[email protected]>
  • Loading branch information
jpsim authored Mar 10, 2023
1 parent e880f4d commit 9c1c4a5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mobile/library/cc/direct_response_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Envoy {
namespace DirectResponseTesting {

// The match operation to perform.
enum MatchMode { contains, exact, prefix, suffix };
enum class MatchMode { Contains, Exact, Prefix, Suffix };

// A configuration for when a header should be matched.
struct HeaderMatcher {
Expand Down
16 changes: 8 additions & 8 deletions mobile/library/cc/engine_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ std::unique_ptr<envoy::config::bootstrap::v3::Bootstrap> EngineBuilder::generate
auto* direct_response_headers = direct_response_route_match->add_headers();
direct_response_headers->set_name(header.name);
switch (header.mode) {
case DirectResponseTesting::contains:
case DirectResponseTesting::MatchMode::Contains:
direct_response_headers->set_contains_match(header.value);
break;
case DirectResponseTesting::exact:
case DirectResponseTesting::MatchMode::Exact:
direct_response_headers->set_exact_match(header.value);
break;
case DirectResponseTesting::prefix:
case DirectResponseTesting::MatchMode::Prefix:
direct_response_headers->set_prefix_match(header.value);
break;
case DirectResponseTesting::suffix:
case DirectResponseTesting::MatchMode::Suffix:
direct_response_headers->set_suffix_match(header.value);
break;
}
Expand Down Expand Up @@ -407,16 +407,16 @@ std::unique_ptr<envoy::config::bootstrap::v3::Bootstrap> EngineBuilder::generate
auto* direct_response_headers = direct_response_route_match->add_headers();
direct_response_headers->set_name(header.name);
switch (header.mode) {
case DirectResponseTesting::contains:
case DirectResponseTesting::MatchMode::Contains:
direct_response_headers->set_contains_match(header.value);
break;
case DirectResponseTesting::exact:
case DirectResponseTesting::MatchMode::Exact:
direct_response_headers->set_exact_match(header.value);
break;
case DirectResponseTesting::prefix:
case DirectResponseTesting::MatchMode::Prefix:
direct_response_headers->set_prefix_match(header.value);
break;
case DirectResponseTesting::suffix:
case DirectResponseTesting::MatchMode::Suffix:
direct_response_headers->set_suffix_match(header.value);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions mobile/library/objective-c/EnvoyConfiguration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ @implementation EMOHeaderMatcher
result.value = [self.value toCXXString];
switch (self.mode) {
case EMOMatchModeContains:
result.mode = Envoy::DirectResponseTesting::contains;
result.mode = Envoy::DirectResponseTesting::MatchMode::Contains;
break;
case EMOMatchModeExact:
result.mode = Envoy::DirectResponseTesting::exact;
result.mode = Envoy::DirectResponseTesting::MatchMode::Exact;
break;
case EMOMatchModePrefix:
result.mode = Envoy::DirectResponseTesting::prefix;
result.mode = Envoy::DirectResponseTesting::MatchMode::Prefix;
break;
case EMOMatchModeSuffix:
result.mode = Envoy::DirectResponseTesting::suffix;
result.mode = Envoy::DirectResponseTesting::MatchMode::Suffix;
break;
}
return result;
Expand Down
9 changes: 0 additions & 9 deletions mobile/library/swift/EnvoyCxxSwiftInterop/cxx_swift_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ inline const LogLevel LogLevelError = LogLevel::err;
inline const LogLevel LogLevelCritical = LogLevel::critical;
inline const LogLevel LogLevelOff = LogLevel::off;

inline const DirectResponseTesting::MatchMode DirectResponseMatchModeContains =
DirectResponseTesting::contains;
inline const DirectResponseTesting::MatchMode DirectResponseMatchModeExact =
DirectResponseTesting::exact;
inline const DirectResponseTesting::MatchMode DirectResponseMatchModePrefix =
DirectResponseTesting::prefix;
inline const DirectResponseTesting::MatchMode DirectResponseMatchModeSuffix =
DirectResponseTesting::suffix;

// Smart pointers aren't currently supported by Swift / C++ interop, so we "erase"
// it into a `BootstrapPtr` / `intptr_t`, which we can import from Swift.
inline BootstrapPtr generateBootstrapPtr(Platform::EngineBuilder builder) {
Expand Down

0 comments on commit 9c1c4a5

Please sign in to comment.