| 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..842d2a398c2646e4c2eeb949abbbfc95a76ae5c0
|
| --- /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 {
|
| +
|
| +std::string ConstructVersionString(std::vector<uint32_t> components) {
|
| + 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
|
| +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
|
|
|