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_InputStreamUtils_h
8 #define mozilla_ipc_InputStreamUtils_h
10 #include "mozilla/ipc/InputStreamParams.h"
12 #include "nsIInputStream.h"
20 // If you want to serialize an inputStream, please use SerializeIPCStream or
21 // nsIInputStream directly.
22 class InputStreamHelper
{
24 static void SerializedComplexity(nsIInputStream
* aInputStream
,
25 uint32_t aMaxSize
, uint32_t* aSizeUsed
,
26 uint32_t* aPipes
, uint32_t* aTransferables
);
28 // These 2 methods allow to serialize an inputStream into InputStreamParams.
29 // The manager is needed in case a stream needs to serialize itself as
31 // The stream serializes itself fully only if the resulting IPC message will
32 // be smaller than |aMaxSize|. Otherwise, the stream serializes itself as a
33 // DataPipe, and, its content will be sent to the other side of the IPC pipe
34 // in chunks. The IPC message size is returned into |aSizeUsed|.
35 static void SerializeInputStream(nsIInputStream
* aInputStream
,
36 InputStreamParams
& aParams
,
37 uint32_t aMaxSize
, uint32_t* aSizeUsed
);
39 // When a stream wants to serialize itself as a DataPipe, it uses this method.
40 static void SerializeInputStreamAsPipe(nsIInputStream
* aInputStream
,
41 InputStreamParams
& aParams
);
43 static already_AddRefed
<nsIInputStream
> DeserializeInputStream(
44 const InputStreamParams
& aParams
);
48 } // namespace mozilla
50 #endif // mozilla_ipc_InputStreamUtils_h