michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIOutputStream.idl" michael@0: michael@0: /** michael@0: * This interface allows writing of primitive data types (integers, michael@0: * floating-point values, booleans, etc.) to a stream in a binary, untagged, michael@0: * fixed-endianness format. This might be used, for example, to implement michael@0: * network protocols or to produce architecture-neutral binary disk files, michael@0: * i.e. ones that can be read and written by both big-endian and little-endian michael@0: * platforms. Output is written in big-endian order (high-order byte first), michael@0: * as this is traditional network order. michael@0: * michael@0: * @See nsIBinaryInputStream michael@0: */ michael@0: michael@0: [scriptable, uuid(204ee610-8765-11d3-90cf-0040056a906e)] michael@0: interface nsIBinaryOutputStream : nsIOutputStream { michael@0: void setOutputStream(in nsIOutputStream aOutputStream); michael@0: michael@0: /** michael@0: * Write a boolean as an 8-bit char to the stream. michael@0: */ michael@0: void writeBoolean(in boolean aBoolean); michael@0: michael@0: void write8(in uint8_t aByte); michael@0: void write16(in uint16_t a16); michael@0: void write32(in uint32_t a32); michael@0: void write64(in uint64_t a64); michael@0: michael@0: void writeFloat(in float aFloat); michael@0: void writeDouble(in double aDouble); michael@0: michael@0: /** michael@0: * Write an 8-bit pascal style string to the stream. michael@0: * 32-bit length field, followed by length 8-bit chars. michael@0: */ michael@0: void writeStringZ(in string aString); michael@0: michael@0: /** michael@0: * Write a 16-bit pascal style string to the stream. michael@0: * 32-bit length field, followed by length PRUnichars. michael@0: */ michael@0: void writeWStringZ(in wstring aString); michael@0: michael@0: /** michael@0: * Write an 8-bit pascal style string (UTF8-encoded) to the stream. michael@0: * 32-bit length field, followed by length 8-bit chars. michael@0: */ michael@0: void writeUtf8Z(in wstring aString); michael@0: michael@0: /** michael@0: * Write an opaque byte array to the stream. michael@0: */ michael@0: void writeBytes([size_is(aLength)] in string aString, in uint32_t aLength); michael@0: michael@0: /** michael@0: * Write an opaque byte array to the stream. michael@0: */ michael@0: void writeByteArray([array, size_is(aLength)] in uint8_t aBytes, michael@0: in uint32_t aLength); michael@0: michael@0: }; michael@0: michael@0: %{C++ michael@0: michael@0: inline nsresult michael@0: NS_WriteOptionalStringZ(nsIBinaryOutputStream* aStream, const char* aString) michael@0: { michael@0: bool nonnull = (aString != nullptr); michael@0: nsresult rv = aStream->WriteBoolean(nonnull); michael@0: if (NS_SUCCEEDED(rv) && nonnull) michael@0: rv = aStream->WriteStringZ(aString); michael@0: return rv; michael@0: } michael@0: michael@0: inline nsresult michael@0: NS_WriteOptionalWStringZ(nsIBinaryOutputStream* aStream, const char16_t* aString) michael@0: { michael@0: bool nonnull = (aString != nullptr); michael@0: nsresult rv = aStream->WriteBoolean(nonnull); michael@0: if (NS_SUCCEEDED(rv) && nonnull) michael@0: rv = aStream->WriteWStringZ(aString); michael@0: return rv; michael@0: } michael@0: michael@0: %}