OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/common/common_custom_types_struct_traits.h" | |
6 | |
7 #include <iterator> | |
8 | |
9 #include "base/version.h" | |
10 | |
11 namespace mojo { | |
12 | |
13 namespace { | |
14 | |
15 std::string ConstructVersionString(const std::vector<uint32_t>& components) { | |
Fady Samuel
2016/07/19 17:33:03
I just looked at base::Version's constructor. It s
Alex Z.
2016/07/26 14:38:55
Done.
| |
16 std::stringstream version_stream; | |
17 for (size_t i = 0; i < components.size(); i++) { | |
18 if (i != 0) | |
19 version_stream << "."; | |
20 | |
21 version_stream << components[i]; | |
22 } | |
23 return version_stream.str(); | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 // static | |
29 const std::vector<uint32_t>& | |
30 StructTraits<mojo::common::mojom::Version, base::Version>::components( | |
31 const base::Version& version) { | |
32 return version.components(); | |
33 } | |
34 | |
35 // static | |
36 bool StructTraits<mojo::common::mojom::Version, base::Version>::Read( | |
37 mojo::common::mojom::VersionDataView data, | |
38 base::Version* out) { | |
39 std::vector<uint32_t> components; | |
40 if (!data.ReadComponents(&components)) | |
41 return false; | |
42 | |
43 *out = base::Version(ConstructVersionString(components)); | |
44 return out->IsValid(); | |
45 } | |
46 | |
47 } // namespace mojo | |
OLD | NEW |