1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include
"nsIOutputStream.idl"
10 template
<class ElementType
, size_t Extent
> class Span
;
13 native Bytes
(mozilla
::Span
<const uint8_t
>);
16 * This interface allows writing of primitive data types (integers,
17 * floating-point values, booleans, etc.) to a stream in a binary, untagged,
18 * fixed-endianness format. This might be used, for example, to implement
19 * network protocols or to produce architecture-neutral binary disk files,
20 * i.e. ones that can be read and written by both big-endian and little-endian
21 * platforms. Output is written in big-endian order (high-order byte first),
22 * as this is traditional network order.
24 * @See nsIBinaryInputStream
27 [scriptable
, builtinclass
, uuid(204ee610
-8765-11d3
-90cf
-0040056a906e
)]
28 interface nsIBinaryOutputStream
: nsIOutputStream
{
29 void setOutputStream
(in nsIOutputStream aOutputStream
);
32 * Write a boolean as an 8-bit char to the stream.
34 void writeBoolean
(in boolean aBoolean
);
36 void write8
(in uint8_t aByte
);
37 void write16
(in uint16_t a16
);
38 void write32
(in uint32_t a32
);
39 void write64
(in uint64_t a64
);
41 void writeFloat
(in float aFloat
);
42 void writeDouble
(in double aDouble
);
45 * Write an 8-bit pascal style string to the stream.
46 * 32-bit length field, followed by length 8-bit chars.
48 void writeStringZ
(in string aString
);
51 * Write a 16-bit pascal style string to the stream.
52 * 32-bit length field, followed by length PRUnichars.
54 void writeWStringZ
(in wstring aString
);
57 * Write an 8-bit pascal style string (UTF8-encoded) to the stream.
58 * 32-bit length field, followed by length 8-bit chars.
60 void writeUtf8Z
(in wstring aString
);
63 * Write an opaque byte array to the stream.
65 [binaryname
(WriteBytesFromJS
)]
66 void writeBytes
([size_is(aLength
)] in string aString
,
67 [optional] in uint32_t aLength
);
70 * Non-scriptable and saner-signature version of the same.
72 [noscript
, nostdcall
, binaryname
(WriteBytes
)]
73 void writeBytesNative
(in Bytes aBytes
);
76 * Write an opaque byte array to the stream.
78 void writeByteArray
(in Array
<uint8_t
> aBytes
);
84 NS_WriteOptionalStringZ
(nsIBinaryOutputStream
* aStream
, const char* aString
)
86 bool nonnull
= (aString
!= nullptr
);
87 nsresult rv
= aStream
->WriteBoolean
(nonnull
);
88 if
(NS_SUCCEEDED
(rv
) && nonnull
)
89 rv
= aStream
->WriteStringZ
(aString
);
94 NS_WriteOptionalWStringZ
(nsIBinaryOutputStream
* aStream
, const char16_t
* aString
)
96 bool nonnull
= (aString
!= nullptr
);
97 nsresult rv
= aStream
->WriteBoolean
(nonnull
);
98 if
(NS_SUCCEEDED
(rv
) && nonnull
)
99 rv
= aStream
->WriteWStringZ
(aString
);