Chromium Code Reviews| Index: mojo/common/common_custom_types_struct_traits.cc |
| diff --git a/mojo/common/common_custom_types_struct_traits.cc b/mojo/common/common_custom_types_struct_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..52d8f5f3dfb4a464b19238f08a7491328e68f73e |
| --- /dev/null |
| +++ b/mojo/common/common_custom_types_struct_traits.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "mojo/common/common_custom_types_struct_traits.h" |
| + |
| +#include <iterator> |
| + |
| +#include "base/version.h" |
| + |
| +namespace mojo { |
| + |
| +namespace { |
| + |
| +const std::string& ConstructVersionString(std::vector<uint32_t> components) { |
|
Fady Samuel
2016/07/19 16:47:40
std::string. This can't be const reference.
The i
Alex Z.
2016/07/19 17:27:12
Done.
|
| + std::stringstream version_stream; |
| + for (size_t i = 0; i < components.size(); i++) { |
| + if (i != 0) |
| + version_stream << "."; |
| + |
| + version_stream << components[i]; |
| + } |
| + return version_stream.str(); |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +const std::vector<uint32_t>& |
| +StructTraits<mojo::common::mojom::Version, base::Version>::components( |
| + const base::Version& version) { |
| + return version.components(); |
| +} |
| + |
| +// static |
| +bool StructTraits<mojo::common::mojom::Version, base::Version>::Read( |
| + mojo::common::mojom::VersionDataView data, |
| + base::Version* out) { |
| + std::vector<uint32_t> components; |
| + if (!data.ReadComponents(&components)) |
| + return false; |
| + |
| + *out = base::Version(ConstructVersionString(components)); |
| + return out->IsValid(); |
| +} |
| + |
| +} // namespace mojo |