1999-11-16 22:12:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-11-16 22:12:41 +03:00
|
|
|
|
|
|
|
#include "nsIOutputStream.idl"
|
|
|
|
|
2019-07-22 23:27:39 +03:00
|
|
|
%{C++
|
|
|
|
namespace mozilla {
|
|
|
|
template<class ElementType, size_t Extent> class Span;
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
native Bytes(mozilla::Span<const uint8_t>);
|
|
|
|
|
1999-11-16 22:12:41 +03:00
|
|
|
/**
|
|
|
|
* This interface allows writing of primitive data types (integers,
|
|
|
|
* floating-point values, booleans, etc.) to a stream in a binary, untagged,
|
|
|
|
* fixed-endianness format. This might be used, for example, to implement
|
|
|
|
* network protocols or to produce architecture-neutral binary disk files,
|
|
|
|
* i.e. ones that can be read and written by both big-endian and little-endian
|
|
|
|
* platforms. Output is written in big-endian order (high-order byte first),
|
|
|
|
* as this is traditional network order.
|
|
|
|
*
|
|
|
|
* @See nsIBinaryInputStream
|
|
|
|
*/
|
|
|
|
|
2020-12-09 05:41:19 +03:00
|
|
|
[scriptable, builtinclass, uuid(204ee610-8765-11d3-90cf-0040056a906e)]
|
1999-11-16 22:12:41 +03:00
|
|
|
interface nsIBinaryOutputStream : nsIOutputStream {
|
|
|
|
void setOutputStream(in nsIOutputStream aOutputStream);
|
2019-05-23 01:37:14 +03:00
|
|
|
|
2006-10-16 12:01:00 +04:00
|
|
|
/**
|
|
|
|
* Write a boolean as an 8-bit char to the stream.
|
|
|
|
*/
|
2011-08-07 09:03:32 +04:00
|
|
|
void writeBoolean(in boolean aBoolean);
|
1999-11-16 22:12:41 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void write8(in uint8_t aByte);
|
|
|
|
void write16(in uint16_t a16);
|
|
|
|
void write32(in uint32_t a32);
|
|
|
|
void write64(in uint64_t a64);
|
1999-11-16 22:12:41 +03:00
|
|
|
|
|
|
|
void writeFloat(in float aFloat);
|
|
|
|
void writeDouble(in double aDouble);
|
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Write an 8-bit pascal style string to the stream.
|
|
|
|
* 32-bit length field, followed by length 8-bit chars.
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
|
|
|
void writeStringZ(in string aString);
|
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Write a 16-bit pascal style string to the stream.
|
|
|
|
* 32-bit length field, followed by length PRUnichars.
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
|
|
|
void writeWStringZ(in wstring aString);
|
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Write an 8-bit pascal style string (UTF8-encoded) to the stream.
|
|
|
|
* 32-bit length field, followed by length 8-bit chars.
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
|
|
|
void writeUtf8Z(in wstring aString);
|
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Write an opaque byte array to the stream.
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
2019-07-22 23:27:39 +03:00
|
|
|
[binaryname(WriteBytesFromJS)]
|
2018-04-22 04:29:33 +03:00
|
|
|
void writeBytes([size_is(aLength)] in string aString,
|
|
|
|
[optional] in uint32_t aLength);
|
2003-03-14 00:23:18 +03:00
|
|
|
|
2019-07-22 17:52:04 +03:00
|
|
|
/**
|
2019-07-22 23:27:39 +03:00
|
|
|
* Non-scriptable and saner-signature version of the same.
|
2019-07-22 17:52:04 +03:00
|
|
|
*/
|
2019-07-22 23:27:39 +03:00
|
|
|
[noscript, nostdcall, binaryname(WriteBytes)]
|
|
|
|
void writeBytesNative(in Bytes aBytes);
|
2019-07-22 21:39:08 +03:00
|
|
|
|
2019-07-22 23:27:39 +03:00
|
|
|
/**
|
|
|
|
* Write an opaque byte array to the stream.
|
|
|
|
*/
|
|
|
|
void writeByteArray(in Array<uint8_t> aBytes);
|
1999-11-16 22:12:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
%{C++
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
inline nsresult
|
|
|
|
NS_WriteOptionalStringZ(nsIBinaryOutputStream* aStream, const char* aString)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
bool nonnull = (aString != nullptr);
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult rv = aStream->WriteBoolean(nonnull);
|
|
|
|
if (NS_SUCCEEDED(rv) && nonnull)
|
|
|
|
rv = aStream->WriteStringZ(aString);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_WriteOptionalWStringZ(nsIBinaryOutputStream* aStream, const char16_t* aString)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
bool nonnull = (aString != nullptr);
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult rv = aStream->WriteBoolean(nonnull);
|
|
|
|
if (NS_SUCCEEDED(rv) && nonnull)
|
|
|
|
rv = aStream->WriteWStringZ(aString);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-11-16 22:12:41 +03:00
|
|
|
%}
|