Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(809)

Unified Diff: mojo/public/cpp/bindings/lib/validation_util.h

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.cc ('k') | mojo/public/cpp/bindings/tests/union_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/validation_util.h
diff --git a/mojo/public/cpp/bindings/lib/validation_util.h b/mojo/public/cpp/bindings/lib/validation_util.h
index 41049c03c9880168d6755ad4d6311dae0fe8fa88..5314a362702924cf7a17b08c8e32139a194b42f7 100644
--- a/mojo/public/cpp/bindings/lib/validation_util.h
+++ b/mojo/public/cpp/bindings/lib/validation_util.h
@@ -124,6 +124,21 @@ bool ValidateHandle(const Handle& input, BoundsChecker* bounds_checker);
bool ValidateAssociatedInterfaceId(InterfaceId input);
+// Checks whether the given enum value is valid. Please note that any value is
+// valid for an extensible enum, although it may be from a newer version and
+// thus unknown.
+template <typename T>
+bool ValidateEnum(const T& input) {
+ if (T::kIsExtensible)
+ return true;
+
+ if (T::IsKnownValue(input.value))
+ return true;
+
+ ReportValidationError(VALIDATION_ERROR_UNKNOWN_ENUM_VALUE);
+ return false;
+}
+
} // namespace internal
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.cc ('k') | mojo/public/cpp/bindings/tests/union_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698