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

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

Issue 1966933002: Mojo C++ bindings: switch the existing usage of StructTraits to use the new data view interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@26_reader
Patch Set: typeid() is not allowed :/ Created 4 years, 7 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
Index: mojo/public/cpp/bindings/lib/serialization_util.h
diff --git a/mojo/public/cpp/bindings/lib/serialization_util.h b/mojo/public/cpp/bindings/lib/serialization_util.h
index 8e926cc5e832803781cf6b8e9a026e4be8ced18f..aa5806722c65fb5feeb304c63330da90d8e495ef 100644
--- a/mojo/public/cpp/bindings/lib/serialization_util.h
+++ b/mojo/public/cpp/bindings/lib/serialization_util.h
@@ -102,20 +102,6 @@ inline void InterfaceDataToPointer(Interface_Data* input,
input->version));
}
-// TODO(yzshen): Unify StructTraits::Read*() methods and remove
-// HasReadFromDataViewMethod.
-template <typename T>
-struct HasReadFromDataViewMethod {
- template <typename U>
- static char Test(decltype(U::ReadFromDataView)*);
- template <typename U>
- static int Test(...);
- static const bool value = sizeof(Test<T>(0)) == sizeof(char);
-
- private:
- EnsureTypeIsComplete<T> check_t_;
-};
-
template <typename T>
struct HasIsNullMethod {
template <typename U>
@@ -143,6 +129,37 @@ template <
bool CallIsNullIfExists(const UserType& input) {
return false;
}
+template <typename T>
+struct HasSetToNullMethod {
+ template <typename U>
+ static char Test(decltype(U::SetToNull)*);
+ template <typename U>
+ static int Test(...);
+ static const bool value = sizeof(Test<T>(0)) == sizeof(char);
+
+ private:
+ EnsureTypeIsComplete<T> check_t_;
+};
+
+template <
+ typename Traits,
+ typename UserType,
+ typename std::enable_if<HasSetToNullMethod<Traits>::value>::type* = nullptr>
+bool CallSetToNullIfExists(UserType* output) {
+ Traits::SetToNull(output);
+ return true;
+}
+
+template <typename Traits,
+ typename UserType,
+ typename std::enable_if<!HasSetToNullMethod<Traits>::value>::type* =
+ nullptr>
+bool CallSetToNullIfExists(UserType* output) {
+ LOG(ERROR) << "A null value is received. But the Struct/Array/StringTraits "
+ << "class doesn't define a SetToNull() function and therefore is "
+ << "unable to deserialize the value.";
+ return false;
+}
template <typename T>
struct HasSetUpContextMethod {

Powered by Google App Engine
This is Rietveld 408576698