OLD | NEW |
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_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
| 11 #include <vector> |
11 | 12 |
12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
13 #include "mojo/public/cpp/bindings/struct_traits.h" | 14 #include "mojo/public/cpp/bindings/struct_traits.h" |
14 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" | 15 #include "mojo/public/cpp/bindings/tests/struct_with_traits_impl.h" |
15 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" | 16 #include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 | 19 |
19 template <> | 20 template <> |
| 21 struct StructTraits<test::NestedStructWithTraits, |
| 22 test::NestedStructWithTraitsImpl> { |
| 23 static bool Read(test::NestedStructWithTraitsDataView data, |
| 24 test::NestedStructWithTraitsImpl* output); |
| 25 static int32_t value(const test::NestedStructWithTraitsImpl& input) { |
| 26 return input.value; |
| 27 } |
| 28 }; |
| 29 |
| 30 template <> |
20 struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> { | 31 struct StructTraits<test::StructWithTraits, test::StructWithTraitsImpl> { |
21 // Deserialization to test::StructTraitsImpl. | 32 // Deserialization to test::StructTraitsImpl. |
22 static bool Read(test::StructWithTraitsDataView data, | 33 static bool Read(test::StructWithTraitsDataView data, |
23 test::StructWithTraitsImpl* out); | 34 test::StructWithTraitsImpl* out); |
24 | 35 |
25 // Fields in test::StructWithTraits. | 36 // Fields in test::StructWithTraits. |
26 // See src/mojo/public/interfaces/bindings/tests/test_native_types.mojom. | 37 // See src/mojo/public/interfaces/bindings/tests/struct_with_traits.mojom. |
27 static bool f_bool(const test::StructWithTraitsImpl& value) { | 38 static bool f_bool(const test::StructWithTraitsImpl& value) { |
28 return value.get_bool(); | 39 return value.get_bool(); |
29 } | 40 } |
30 | 41 |
31 static uint32_t f_uint32(const test::StructWithTraitsImpl& value) { | 42 static uint32_t f_uint32(const test::StructWithTraitsImpl& value) { |
32 return value.get_uint32(); | 43 return value.get_uint32(); |
33 } | 44 } |
34 | 45 |
35 static uint64_t f_uint64(const test::StructWithTraitsImpl& value) { | 46 static uint64_t f_uint64(const test::StructWithTraitsImpl& value) { |
36 return value.get_uint64(); | 47 return value.get_uint64(); |
37 } | 48 } |
38 | 49 |
39 static base::StringPiece f_string(const test::StructWithTraitsImpl& value) { | 50 static base::StringPiece f_string(const test::StructWithTraitsImpl& value) { |
| 51 return value.get_string_as_string_piece(); |
| 52 } |
| 53 |
| 54 static const std::string& f_string2(const test::StructWithTraitsImpl& value) { |
40 return value.get_string(); | 55 return value.get_string(); |
41 } | 56 } |
42 | 57 |
43 static base::StringPiece f_string2(const test::StructWithTraitsImpl& value) { | 58 static const std::vector<std::string>& f_string_array( |
44 return value.get_string(); | 59 const test::StructWithTraitsImpl& value) { |
| 60 return value.get_string_array(); |
| 61 } |
| 62 |
| 63 static const test::NestedStructWithTraitsImpl& f_struct( |
| 64 const test::StructWithTraitsImpl& value) { |
| 65 return value.get_struct(); |
| 66 } |
| 67 |
| 68 static const std::vector<test::NestedStructWithTraitsImpl>& f_struct_array( |
| 69 const test::StructWithTraitsImpl& value) { |
| 70 return value.get_struct_array(); |
45 } | 71 } |
46 }; | 72 }; |
47 | 73 |
48 } // namespace mojo | 74 } // namespace mojo |
49 | 75 |
50 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ | 76 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_STRUCT_WITH_TRAITS_IMPL_TRAITS_H_ |
OLD | NEW |