OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #ifndef CHROME_COMMON_EXTENSIONS_MEDIA_PARSER_STRUCT_TRAITS_H_ | |
6 #define CHROME_COMMON_EXTENSIONS_MEDIA_PARSER_STRUCT_TRAITS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "chrome/common/extensions/media_parser.mojom.h" | |
11 #include "chrome/common/media_galleries/metadata_types.h" | |
12 #include "mojo/public/cpp/bindings/array_data_view.h" | |
13 #include "mojo/public/cpp/bindings/array_traits_carray.h" | |
14 | |
15 namespace mojo { | |
16 | |
17 template <> | |
18 struct StructTraits<extensions::mojom::AttachedImageDataView, | |
19 ::metadata::AttachedImage> { | |
20 static const std::string& type(const ::metadata::AttachedImage& image) { | |
21 return image.type; | |
22 } | |
23 | |
24 static ConstCArray<uint8_t> data(const ::metadata::AttachedImage& image) { | |
25 return ConstCArray<uint8_t>( | |
26 image.data.size(), reinterpret_cast<const uint8_t*>(image.data.data())); | |
dcheng
2017/01/11 09:09:59
Mind adding a TODO to pass the actual image data a
Noel Gordon
2017/01/12 14:11:20
Good idea, done.
| |
27 } | |
28 | |
29 static bool Read(extensions::mojom::AttachedImageDataView view, | |
30 ::metadata::AttachedImage* out) { | |
dcheng
2017/01/11 09:09:59
Nit: please out-of-line this into a .cc file
Noel Gordon
2017/01/12 14:11:20
Done. Added chrome/common/extensions/media_parser
| |
31 if (!view.ReadType(&out->type)) | |
32 return false; | |
33 | |
34 ArrayDataView<uint8_t> data; | |
35 view.GetDataDataView(&data); | |
36 | |
37 out->data.assign(reinterpret_cast<const char*>(data.data()), data.size()); | |
38 return true; | |
39 } | |
40 }; | |
41 | |
42 } // namespace mojo | |
43 | |
44 #endif // CHROME_COMMON_EXTENSIONS_MEDIA_PARSER_STRUCT_TRAITS_H_ | |
OLD | NEW |