Bug 1910362 - Create new Nimbus helper r=aaronmt,ohorvath
[gecko.git] / xpcom / io / nsBinaryStream.h
blob94b92bb74613e0ffea1b13ad192025413f0f949e
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 nsBinaryStream_h___
8 #define nsBinaryStream_h___
10 #include "nsCOMPtr.h"
11 #include "nsAString.h"
12 #include "nsIObjectInputStream.h"
13 #include "nsIObjectOutputStream.h"
14 #include "nsIStreamBufferAccess.h"
16 #define NS_BINARYOUTPUTSTREAM_CID \
17 { /* 86c37b9a-74e7-4672-844e-6e7dd83ba484 */ \
18 0x86c37b9a, 0x74e7, 0x4672, { \
19 0x84, 0x4e, 0x6e, 0x7d, 0xd8, 0x3b, 0xa4, 0x84 \
20 } \
23 #define NS_BINARYOUTPUTSTREAM_CONTRACTID "@mozilla.org/binaryoutputstream;1"
25 // Derive from nsIObjectOutputStream so this class can be used as a superclass
26 // by nsObjectOutputStream.
27 class nsBinaryOutputStream final : public nsIObjectOutputStream {
28 public:
29 nsBinaryOutputStream() = default;
31 protected:
32 friend already_AddRefed<nsIObjectOutputStream> NS_NewObjectOutputStream(
33 nsIOutputStream*);
35 // nsISupports methods
36 NS_DECL_ISUPPORTS
38 // nsIOutputStream methods
39 NS_DECL_NSIOUTPUTSTREAM
41 // nsIBinaryOutputStream methods
42 NS_DECL_NSIBINARYOUTPUTSTREAM
44 // nsIObjectOutputStream methods
45 NS_DECL_NSIOBJECTOUTPUTSTREAM
47 // Call Write(), ensuring that all proffered data is written
48 nsresult WriteFully(const char* aBuf, uint32_t aCount);
50 nsCOMPtr<nsIOutputStream> mOutputStream;
51 nsCOMPtr<nsIStreamBufferAccess> mBufferAccess;
53 private:
54 // virtual dtor since subclasses call our Release()
55 virtual ~nsBinaryOutputStream() = default;
58 #define NS_BINARYINPUTSTREAM_CID \
59 { /* c521a612-2aad-46db-b6ab-3b821fb150b1 */ \
60 0xc521a612, 0x2aad, 0x46db, { \
61 0xb6, 0xab, 0x3b, 0x82, 0x1f, 0xb1, 0x50, 0xb1 \
62 } \
65 #define NS_BINARYINPUTSTREAM_CONTRACTID "@mozilla.org/binaryinputstream;1"
67 class nsBinaryInputStream final : public nsIObjectInputStream {
68 public:
69 nsBinaryInputStream() = default;
71 protected:
72 friend already_AddRefed<nsIObjectInputStream> NS_NewObjectInputStream(
73 nsIInputStream*);
75 // nsISupports methods
76 NS_DECL_ISUPPORTS
78 // nsIInputStream methods
79 NS_DECL_NSIINPUTSTREAM
81 // nsIBinaryInputStream methods
82 NS_DECL_NSIBINARYINPUTSTREAM
84 // nsIObjectInputStream methods
85 NS_DECL_NSIOBJECTINPUTSTREAM
87 nsCOMPtr<nsIInputStream> mInputStream;
88 nsCOMPtr<nsIStreamBufferAccess> mBufferAccess;
90 private:
91 // Shared infrastructure for ReadBytes and ReadByteArray. Callers
92 // are expected to provide a buffer that can contain aLength bytes.
93 nsresult ReadBytesToBuffer(uint32_t aLength, uint8_t* aBuffer);
95 // virtual dtor since subclasses call our Release()
96 virtual ~nsBinaryInputStream() = default;
99 #endif // nsBinaryStream_h___