xref: /aosp_15_r20/external/libchrome/ipc/message_mojom_traits.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2018 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "ipc/message_mojom_traits.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker #include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
8*635a8641SAndroid Build Coastguard Worker 
9*635a8641SAndroid Build Coastguard Worker namespace mojo {
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker // static
12*635a8641SAndroid Build Coastguard Worker mojo_base::BigBufferView
buffer(IPC::MessageView & view)13*635a8641SAndroid Build Coastguard Worker StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::buffer(
14*635a8641SAndroid Build Coastguard Worker     IPC::MessageView& view) {
15*635a8641SAndroid Build Coastguard Worker   return view.TakeBufferView();
16*635a8641SAndroid Build Coastguard Worker }
17*635a8641SAndroid Build Coastguard Worker 
18*635a8641SAndroid Build Coastguard Worker // static
19*635a8641SAndroid Build Coastguard Worker base::Optional<std::vector<mojo::native::SerializedHandlePtr>>
handles(IPC::MessageView & view)20*635a8641SAndroid Build Coastguard Worker StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::handles(
21*635a8641SAndroid Build Coastguard Worker     IPC::MessageView& view) {
22*635a8641SAndroid Build Coastguard Worker   return view.TakeHandles();
23*635a8641SAndroid Build Coastguard Worker }
24*635a8641SAndroid Build Coastguard Worker 
25*635a8641SAndroid Build Coastguard Worker // static
Read(IPC::mojom::MessageDataView data,IPC::MessageView * out)26*635a8641SAndroid Build Coastguard Worker bool StructTraits<IPC::mojom::MessageDataView, IPC::MessageView>::Read(
27*635a8641SAndroid Build Coastguard Worker     IPC::mojom::MessageDataView data,
28*635a8641SAndroid Build Coastguard Worker     IPC::MessageView* out) {
29*635a8641SAndroid Build Coastguard Worker   mojo_base::BigBufferView buffer_view;
30*635a8641SAndroid Build Coastguard Worker   if (!data.ReadBuffer(&buffer_view))
31*635a8641SAndroid Build Coastguard Worker     return false;
32*635a8641SAndroid Build Coastguard Worker   base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles;
33*635a8641SAndroid Build Coastguard Worker   if (!data.ReadHandles(&handles))
34*635a8641SAndroid Build Coastguard Worker     return false;
35*635a8641SAndroid Build Coastguard Worker 
36*635a8641SAndroid Build Coastguard Worker   *out = IPC::MessageView(std::move(buffer_view), std::move(handles));
37*635a8641SAndroid Build Coastguard Worker   return true;
38*635a8641SAndroid Build Coastguard Worker }
39*635a8641SAndroid Build Coastguard Worker 
40*635a8641SAndroid Build Coastguard Worker }  // namespace mojo
41