1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_IPDLParamTraits_h
8 #define mozilla_ipc_IPDLParamTraits_h
10 #include "chrome/common/ipc_message_utils.h"
11 #include "ipc/IPCMessageUtilsSpecializations.h"
12 #include "mozilla/UniquePtr.h"
13 #include "mozilla/Variant.h"
17 #include <type_traits>
25 // IPDLParamTraits was an extended version of ParamTraits. Unlike ParamTraits,
26 // IPDLParamTraits passes an additional IProtocol* argument to the
27 // write and read methods.
29 // Previously this was required for serializing and deserializing types which
30 // require knowledge of which protocol they're being sent over, however the
31 // actor is now available through `IPC::Message{Writer,Reader}::GetActor()` so
32 // the extra argument is no longer necessary. Please use `IPC::ParamTraits` in
35 // Types which implement IPDLParamTraits are also supported by ParamTraits.
38 struct IPDLParamTraits
{};
41 // WriteIPDLParam and ReadIPDLParam are like IPC::WriteParam and IPC::ReadParam,
42 // however, they also accept a redundant extra actor argument.
44 // NOTE: WriteIPDLParam takes a universal reference, so that it can support
45 // whatever reference type is supported by the underlying ParamTraits::Write
49 static MOZ_NEVER_INLINE
void WriteIPDLParam(IPC::MessageWriter
* aWriter
,
50 IProtocol
* aActor
, P
&& aParam
) {
51 MOZ_ASSERT(aActor
== aWriter
->GetActor());
52 IPC::WriteParam(aWriter
, std::forward
<P
>(aParam
));
56 static MOZ_NEVER_INLINE
bool ReadIPDLParam(IPC::MessageReader
* aReader
,
57 IProtocol
* aActor
, P
* aResult
) {
58 MOZ_ASSERT(aActor
== aReader
->GetActor());
59 return IPC::ReadParam(aReader
, aResult
);
63 } // namespace mozilla
65 #endif // defined(mozilla_ipc_IPDLParamTraits_h)