Bumping manifests a=b2g-bump
[gecko.git] / xpcom / io / nsIBinaryOutputStream.idl
blob4d426d580e9e295386737d2dc3d563a3f73ff094
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"
8 /**
9 * This interface allows writing of primitive data types (integers,
10 * floating-point values, booleans, etc.) to a stream in a binary, untagged,
11 * fixed-endianness format. This might be used, for example, to implement
12 * network protocols or to produce architecture-neutral binary disk files,
13 * i.e. ones that can be read and written by both big-endian and little-endian
14 * platforms. Output is written in big-endian order (high-order byte first),
15 * as this is traditional network order.
17 * @See nsIBinaryInputStream
20 [scriptable, uuid(204ee610-8765-11d3-90cf-0040056a906e)]
21 interface nsIBinaryOutputStream : nsIOutputStream {
22 void setOutputStream(in nsIOutputStream aOutputStream);
24 /**
25 * Write a boolean as an 8-bit char to the stream.
27 void writeBoolean(in boolean aBoolean);
29 void write8(in uint8_t aByte);
30 void write16(in uint16_t a16);
31 void write32(in uint32_t a32);
32 void write64(in uint64_t a64);
34 void writeFloat(in float aFloat);
35 void writeDouble(in double aDouble);
37 /**
38 * Write an 8-bit pascal style string to the stream.
39 * 32-bit length field, followed by length 8-bit chars.
41 void writeStringZ(in string aString);
43 /**
44 * Write a 16-bit pascal style string to the stream.
45 * 32-bit length field, followed by length PRUnichars.
47 void writeWStringZ(in wstring aString);
49 /**
50 * Write an 8-bit pascal style string (UTF8-encoded) to the stream.
51 * 32-bit length field, followed by length 8-bit chars.
53 void writeUtf8Z(in wstring aString);
55 /**
56 * Write an opaque byte array to the stream.
58 void writeBytes([size_is(aLength)] in string aString, in uint32_t aLength);
60 /**
61 * Write an opaque byte array to the stream.
63 void writeByteArray([array, size_is(aLength)] in uint8_t aBytes,
64 in uint32_t aLength);
68 %{C++
70 inline nsresult
71 NS_WriteOptionalStringZ(nsIBinaryOutputStream* aStream, const char* aString)
73 bool nonnull = (aString != nullptr);
74 nsresult rv = aStream->WriteBoolean(nonnull);
75 if (NS_SUCCEEDED(rv) && nonnull)
76 rv = aStream->WriteStringZ(aString);
77 return rv;
80 inline nsresult
81 NS_WriteOptionalWStringZ(nsIBinaryOutputStream* aStream, const char16_t* aString)
83 bool nonnull = (aString != nullptr);
84 nsresult rv = aStream->WriteBoolean(nonnull);
85 if (NS_SUCCEEDED(rv) && nonnull)
86 rv = aStream->WriteWStringZ(aString);
87 return rv;