1 // Copyright 2017 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_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ 6 #define MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ 7 8 #include <stdint.h> 9 #include <vector> 10 11 #include "mojo/common/string16.mojom.h" 12 #include "mojo/public/cpp/bindings/struct_traits.h" 13 14 namespace mojo { 15 16 template <> 17 struct StructTraits<common::mojom::String16, base::string16> { 18 static std::vector<uint16_t> data(const base::string16& str) { 19 const uint16_t* base = str.data(); 20 return std::vector<uint16_t>(base, base + str.size()); 21 } 22 static bool Read(common::mojom::String16DataView data, base::string16* output); 23 }; 24 25 } // mojo 26 27 #endif // MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ 28