no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / ipc / glue / IPCStreamUtils.h
blobc681f7cf1a2fa48665c6ce62c27087c8ae4f937e
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"
11 #include "nsCOMPtr.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
22 // fallible.
23 [[nodiscard]] bool SerializeIPCStream(
24 already_AddRefed<nsIInputStream> aInputStream, IPCStream& aValue,
25 bool aAllowLazy);
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
41 namespace IPC {
43 template <>
44 struct ParamTraits<nsIInputStream*> {
45 static void Write(MessageWriter* aWriter, nsIInputStream* aParam);
46 static bool Read(MessageReader* aReader, RefPtr<nsIInputStream>* aResult);
49 } // namespace IPC
51 #endif // mozilla_ipc_IPCStreamUtils_h