xref: /aosp_15_r20/external/cronet/ipc/message_view.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
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 IPC_MESSAGE_VIEW_H_
6 #define IPC_MESSAGE_VIEW_H_
7 
8 #include <optional>
9 #include <vector>
10 
11 #include "base/component_export.h"
12 #include "base/containers/span.h"
13 #include "ipc/ipc_message.h"
14 #include "mojo/public/interfaces/bindings/native_struct.mojom-forward.h"
15 
16 namespace IPC {
17 
COMPONENT_EXPORT(IPC_MOJOM)18 class COMPONENT_EXPORT(IPC_MOJOM) MessageView {
19  public:
20   MessageView();
21   MessageView(
22       base::span<const uint8_t> bytes,
23       std::optional<std::vector<mojo::native::SerializedHandlePtr>> handles);
24   MessageView(MessageView&&);
25 
26   MessageView(const MessageView&) = delete;
27   MessageView& operator=(const MessageView&) = delete;
28 
29   ~MessageView();
30 
31   MessageView& operator=(MessageView&&);
32 
33   base::span<const uint8_t> bytes() const { return bytes_; }
34   std::optional<std::vector<mojo::native::SerializedHandlePtr>> TakeHandles();
35 
36  private:
37   base::span<const uint8_t> bytes_;
38   std::optional<std::vector<mojo::native::SerializedHandlePtr>> handles_;
39 };
40 
41 }  // namespace IPC
42 
43 #endif  // IPC_MESSAGE_VIEW_H_
44