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

Unified Diff: mojo/public/cpp/bindings/string_traits.h

Issue 1968623002: Mojo C++ bindings: expose public <struct>DataView and StringDataView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_totally_new
Patch Set: 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/string_traits.h
diff --git a/mojo/public/cpp/bindings/string_traits.h b/mojo/public/cpp/bindings/string_traits.h
index c046854c2fb2b39acba1471ac2d91fd2f0d1060c..f0c4275c26497b3df8396efd866c05c8a4901078 100644
--- a/mojo/public/cpp/bindings/string_traits.h
+++ b/mojo/public/cpp/bindings/string_traits.h
@@ -5,8 +5,34 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/lib/array_internal.h"
+
namespace mojo {
+// Access to a string inside a mojo message.
+class StringDataView {
+ public:
+ explicit StringDataView(internal::String_Data* data) : data_(data) {}
+
+ // Whether the data represents a null string.
+ // Note: Must not access the following methods if this method returns true.
+ bool is_null() const { return !data_; }
+
+ const char* storage() const {
+ DCHECK(!is_null());
+ return data_->storage();
+ }
+
+ size_t size() const {
+ DCHECK(!is_null());
+ return data_->size();
+ }
+
+ private:
+ internal::String_Data* data_;
+};
+
// This must be specialized for any UserType to be serialized/deserialized as
// a mojom string.
//
« no previous file with comments | « mojo/public/cpp/bindings/lib/string_traits_wtf.cc ('k') | mojo/public/cpp/bindings/string_traits_standard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698