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_IPCStreamUtils_h
8 #define mozilla_ipc_IPCStreamUtils_h
10 #include "mozilla/ipc/IPCStream.h"
12 #include "nsIInputStream.h"
14 namespace mozilla::ipc
{
16 // Serialize an IPCStream to be sent over IPC fallibly.
18 // If |aAllowLazy| is true the stream may be serialized as a
19 // RemoteLazyInputStream when being sent from child to parent.
21 // ParamTraits<nsIInputStream> may be used instead if serialization cannot be
23 [[nodiscard
]] bool SerializeIPCStream(
24 already_AddRefed
<nsIInputStream
> aInputStream
, IPCStream
& aValue
,
27 // If serialization fails, `aValue` will be initialized to `Nothing()`, so this
28 // return value is safe to ignore.
29 bool SerializeIPCStream(already_AddRefed
<nsIInputStream
> aInputStream
,
30 Maybe
<IPCStream
>& aValue
, bool aAllowLazy
);
32 // Deserialize an IPCStream received from an actor call. These methods
33 // work in both the child and parent.
34 already_AddRefed
<nsIInputStream
> DeserializeIPCStream(const IPCStream
& aValue
);
36 already_AddRefed
<nsIInputStream
> DeserializeIPCStream(
37 const Maybe
<IPCStream
>& aValue
);
39 } // namespace mozilla::ipc
44 struct ParamTraits
<nsIInputStream
*> {
45 static void Write(MessageWriter
* aWriter
, nsIInputStream
* aParam
);
46 static bool Read(MessageReader
* aReader
, RefPtr
<nsIInputStream
>* aResult
);
51 #endif // mozilla_ipc_IPCStreamUtils_h