• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 MOJO_PUBLIC_CPP_BASE_BIG_BUFFER_MOJOM_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BASE_BIG_BUFFER_MOJOM_TRAITS_H_
7 
8 #include <cstdint>
9 #include <vector>
10 
11 #include "base/component_export.h"
12 #include "base/containers/span.h"
13 #include "base/macros.h"
14 #include "mojo/public/cpp/base/big_buffer.h"
15 #include "mojo/public/cpp/bindings/union_traits.h"
16 #include "mojo/public/cpp/system/buffer.h"
17 #include "mojo/public/mojom/base/big_buffer.mojom-shared.h"
18 
19 namespace mojo {
20 
21 template <>
COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)22 struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
23     StructTraits<mojo_base::mojom::BigBufferSharedMemoryRegionDataView,
24                  mojo_base::internal::BigBufferSharedMemoryRegion> {
25   static uint32_t size(
26       const mojo_base::internal::BigBufferSharedMemoryRegion& region);
27   static mojo::ScopedSharedBufferHandle buffer_handle(
28       mojo_base::internal::BigBufferSharedMemoryRegion& region);
29 
30   static bool Read(mojo_base::mojom::BigBufferSharedMemoryRegionDataView data,
31                    mojo_base::internal::BigBufferSharedMemoryRegion* out);
32 };
33 
34 template <>
COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)35 struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
36     UnionTraits<mojo_base::mojom::BigBufferDataView, mojo_base::BigBuffer> {
37   static mojo_base::mojom::BigBufferDataView::Tag GetTag(
38       const mojo_base::BigBuffer& buffer);
39 
40   static const std::vector<uint8_t>& bytes(const mojo_base::BigBuffer& buffer);
41   static mojo_base::internal::BigBufferSharedMemoryRegion& shared_memory(
42       mojo_base::BigBuffer& buffer);
43 
44   static bool Read(mojo_base::mojom::BigBufferDataView data,
45                    mojo_base::BigBuffer* out);
46 };
47 
48 template <>
COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)49 struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
50     UnionTraits<mojo_base::mojom::BigBufferDataView, mojo_base::BigBufferView> {
51   static mojo_base::mojom::BigBufferDataView::Tag GetTag(
52       const mojo_base::BigBufferView& view);
53 
54   static base::span<const uint8_t> bytes(const mojo_base::BigBufferView& view);
55   static mojo_base::internal::BigBufferSharedMemoryRegion& shared_memory(
56       mojo_base::BigBufferView& view);
57 
58   static bool Read(mojo_base::mojom::BigBufferDataView data,
59                    mojo_base::BigBufferView* out);
60 };
61 
62 }  // namespace mojo
63 
64 #endif  // MOJO_PUBLIC_CPP_BASE_BIG_BUFFER_MOJOM_TRAITS_H_
65