• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef MOJO_PUBLIC_CPP_BASE_STRING16_MOJOM_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BASE_STRING16_MOJOM_TRAITS_H_
7 
8 #include <cstdint>
9 
10 #include "base/component_export.h"
11 #include "base/containers/span.h"
12 #include "base/strings/string_piece.h"
13 #include "mojo/public/cpp/base/big_buffer.h"
14 #include "mojo/public/cpp/bindings/struct_traits.h"
15 #include "mojo/public/mojom/base/string16.mojom-shared.h"
16 
17 namespace mojo {
18 
19 template <>
COMPONENT_EXPORT(MOJO_BASE_MOJOM)20 struct COMPONENT_EXPORT(MOJO_BASE_MOJOM)
21     StructTraits<mojo_base::mojom::String16DataView, base::StringPiece16> {
22   static base::span<const uint16_t> data(base::StringPiece16 str) {
23     return base::make_span(reinterpret_cast<const uint16_t*>(str.data()),
24                            str.size());
25   }
26 };
27 
28 template <>
COMPONENT_EXPORT(MOJO_BASE_MOJOM)29 struct COMPONENT_EXPORT(MOJO_BASE_MOJOM)
30     StructTraits<mojo_base::mojom::String16DataView, base::string16> {
31   static base::span<const uint16_t> data(const base::string16& str) {
32     return StructTraits<mojo_base::mojom::String16DataView,
33                         base::StringPiece16>::data(str);
34   }
35 
36   static bool Read(mojo_base::mojom::String16DataView data,
37                    base::string16* out);
38 };
39 
40 template <>
COMPONENT_EXPORT(MOJO_BASE_MOJOM)41 struct COMPONENT_EXPORT(MOJO_BASE_MOJOM)
42     StructTraits<mojo_base::mojom::BigString16DataView, base::string16> {
43   static mojo_base::BigBuffer data(const base::string16& str);
44 
45   static bool Read(mojo_base::mojom::BigString16DataView data,
46                    base::string16* out);
47 };
48 
49 }  // namespace mojo
50 
51 #endif  // MOJO_PUBLIC_CPP_BASE_STRING16_MOJOM_TRAITS_H_
52