Chromium Code Reviews| 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 #include "mojo/common/common_custom_types_struct_traits.h" | 5 #include "mojo/common/common_custom_types_struct_traits.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 namespace mojo { | 9 namespace mojo { |
| 10 | 10 |
| 11 // static | 11 // static |
| 12 std::vector<uint16_t> | |
| 13 StructTraits<mojo::common::mojom::String16DataView, base::string16>::data( | |
| 14 const base::string16& str) { | |
| 15 return std::vector<uint16_t>(str.data(), str.data() + str.size()); | |
| 16 } | |
| 17 | |
| 18 // static | |
| 19 bool StructTraits<mojo::common::mojom::String16DataView, base::string16>::Read( | |
| 20 mojo::common::mojom::String16DataView data, | |
| 21 base::string16* out) { | |
| 22 std::vector<uint16_t> raw_data; | |
| 23 if (!data.ReadData(&raw_data)) | |
|
Ken Rockot(use gerrit already)
2016/10/04 06:28:40
To esprehn@'s point, you can do:
mojo::ArrayDat
Zhiqiang Zhang (Slow)
2016/10/04 10:07:18
Hmm, seems like I can do something similar to
"moj
Zhiqiang Zhang (Slow)
2016/10/04 13:21:59
OK, I decided not to do that.
I found that StringT
| |
| 24 return false; | |
| 25 out->assign(reinterpret_cast<base::char16*>(raw_data.data()), | |
| 26 raw_data.size()); | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 // static | |
| 12 const std::vector<uint32_t>& | 31 const std::vector<uint32_t>& |
| 13 StructTraits<mojo::common::mojom::VersionDataView, base::Version>::components( | 32 StructTraits<mojo::common::mojom::VersionDataView, base::Version>::components( |
| 14 const base::Version& version) { | 33 const base::Version& version) { |
| 15 return version.components(); | 34 return version.components(); |
| 16 } | 35 } |
| 17 | 36 |
| 18 // static | 37 // static |
| 19 bool StructTraits<mojo::common::mojom::VersionDataView, base::Version>::Read( | 38 bool StructTraits<mojo::common::mojom::VersionDataView, base::Version>::Read( |
| 20 mojo::common::mojom::VersionDataView data, | 39 mojo::common::mojom::VersionDataView data, |
| 21 base::Version* out) { | 40 base::Version* out) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 37 | 56 |
| 38 // Receiving a zeroed UnguessableToken is a security issue. | 57 // Receiving a zeroed UnguessableToken is a security issue. |
| 39 if (high == 0 && low == 0) | 58 if (high == 0 && low == 0) |
| 40 return false; | 59 return false; |
| 41 | 60 |
| 42 *out = base::UnguessableToken::Deserialize(high, low); | 61 *out = base::UnguessableToken::Deserialize(high, low); |
| 43 return true; | 62 return true; |
| 44 } | 63 } |
| 45 | 64 |
| 46 } // namespace mojo | 65 } // namespace mojo |
| OLD | NEW |