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

Side by Side Diff: mojo/public/cpp/bindings/string_traits_standard.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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_
7 7
8 #include "mojo/public/cpp/bindings/string.h" 8 #include "mojo/public/cpp/bindings/string.h"
9 #include "mojo/public/cpp/bindings/string_traits.h" 9 #include "mojo/public/cpp/bindings/string_traits.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 template <> 13 template <>
14 struct StringTraits<String> { 14 struct StringTraits<String> {
15 static bool IsNull(const String& input) { return input.is_null(); } 15 static bool IsNull(const String& input) { return input.is_null(); }
16 16
17 static size_t GetSize(const String& input) { return input.size(); } 17 static size_t GetSize(const String& input) { return input.size(); }
18 18
19 static const char* GetData(const String& input) { return input.data(); } 19 static const char* GetData(const String& input) { return input.data(); }
20 20
21 // TODO(yzshen): Use a public type, such as mojo::String::DataView, for 21 static bool Read(StringDataView input, String* output) {
22 // |input|. 22 if (!input.is_null()) {
23 static bool Read(internal::String_Data* input, String* output) { 23 String result(input.storage(), input.size());
24 if (input) {
25 String result(input->storage(), input->size());
26 result.Swap(output); 24 result.Swap(output);
27 } else { 25 } else {
28 *output = nullptr; 26 *output = nullptr;
29 } 27 }
30 return true; 28 return true;
31 } 29 }
32 }; 30 };
33 31
34 } // namespace mojo 32 } // namespace mojo
35 33
36 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_ 34 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STANDARD_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/string_traits.h ('k') | mojo/public/cpp/bindings/string_traits_string_piece.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698