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
|
|
|
|
2000-08-22 11:03:33 +04:00
|
|
|
#include "nsIInputStream.idl"
|
1999-11-16 22:12:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This interface allows consumption of primitive data types from a "binary
|
|
|
|
* stream" containing untagged, big-endian binary data, i.e. as produced by an
|
|
|
|
* implementation of nsIBinaryOutputStream. This might be used, for example,
|
|
|
|
* to implement network protocols or to read from architecture-neutral disk
|
|
|
|
* files, i.e. ones that can be read and written by both big-endian and
|
|
|
|
* little-endian platforms.
|
|
|
|
*
|
|
|
|
* @See nsIBinaryOutputStream
|
|
|
|
*/
|
|
|
|
|
2014-05-23 00:56:56 +04:00
|
|
|
[scriptable, uuid(899b826b-2eb3-469c-8b31-4c29f5d341a6)]
|
1999-11-16 22:12:41 +03:00
|
|
|
interface nsIBinaryInputStream : nsIInputStream {
|
|
|
|
void setInputStream(in nsIInputStream aInputStream);
|
|
|
|
|
2006-10-16 12:01:00 +04:00
|
|
|
/**
|
|
|
|
* Read 8-bits from the stream.
|
|
|
|
*
|
|
|
|
* @return that byte to be treated as a boolean.
|
|
|
|
*/
|
2011-08-07 09:03:32 +04:00
|
|
|
boolean readBoolean();
|
1999-11-16 22:12:41 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t read8();
|
|
|
|
uint16_t read16();
|
|
|
|
uint32_t read32();
|
|
|
|
uint64_t read64();
|
1999-11-16 22:12:41 +03:00
|
|
|
|
|
|
|
float readFloat();
|
|
|
|
double readDouble();
|
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Read an 8-bit pascal style string from the stream.
|
|
|
|
* 32-bit length field, followed by length 8-bit chars.
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
2002-11-14 21:16:31 +03:00
|
|
|
ACString readCString();
|
1999-11-16 22:12:41 +03:00
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Read an 16-bit pascal style string from the stream.
|
|
|
|
* 32-bit length field, followed by length PRUnichars.
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
2002-11-14 21:16:31 +03:00
|
|
|
AString readString();
|
1999-11-16 22:12:41 +03:00
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Read an opaque byte array from the stream.
|
|
|
|
*
|
|
|
|
* @param aLength the number of bytes that must be read.
|
|
|
|
*
|
|
|
|
* @throws NS_ERROR_FAILURE if it can't read aLength bytes
|
1999-11-16 22:12:41 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
void readBytes(in uint32_t aLength,
|
2003-03-14 00:23:18 +03:00
|
|
|
[size_is(aLength), retval] out string aString);
|
|
|
|
|
|
|
|
/**
|
2006-10-16 12:01:00 +04:00
|
|
|
* Read an opaque byte array from the stream, storing the results
|
2003-03-14 00:23:18 +03:00
|
|
|
* as an array of PRUint8s.
|
2006-10-16 12:01:00 +04:00
|
|
|
*
|
|
|
|
* @param aLength the number of bytes that must be read.
|
|
|
|
*
|
|
|
|
* @throws NS_ERROR_FAILURE if it can't read aLength bytes
|
2003-03-14 00:23:18 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
void readByteArray(in uint32_t aLength,
|
|
|
|
[array, size_is(aLength), retval] out uint8_t aBytes);
|
2013-04-19 13:25:33 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read opaque bytes from the stream, storing the results in an ArrayBuffer.
|
|
|
|
*
|
|
|
|
* @param aLength the number of bytes that must be read
|
2013-04-23 01:33:55 +04:00
|
|
|
* @param aArrayBuffer the arraybuffer in which to store the results
|
|
|
|
* Note: passing view.buffer, where view is an ArrayBufferView of an
|
|
|
|
* ArrayBuffer, is not valid unless view.byteOffset == 0.
|
2013-04-19 13:25:33 +04:00
|
|
|
*
|
2014-05-23 00:56:56 +04:00
|
|
|
* @return The number of bytes actually read into aArrayBuffer.
|
2013-04-19 13:25:33 +04:00
|
|
|
*/
|
|
|
|
[implicit_jscontext]
|
2014-05-23 00:56:56 +04:00
|
|
|
unsigned long readArrayBuffer(in uint32_t aLength, in jsval aArrayBuffer);
|
1999-11-16 22:12:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
%{C++
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2005-10-20 20:39:24 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
inline nsresult
|
2002-11-14 21:16:31 +03:00
|
|
|
NS_ReadOptionalCString(nsIBinaryInputStream* aStream, nsACString& aResult)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nonnull;
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult rv = aStream->ReadBoolean(&nonnull);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nonnull)
|
2002-11-14 21:16:31 +03:00
|
|
|
rv = aStream->ReadCString(aResult);
|
2001-07-31 23:05:34 +04:00
|
|
|
else
|
2002-11-14 21:16:31 +03:00
|
|
|
aResult.Truncate();
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsresult
|
2002-11-14 21:16:31 +03:00
|
|
|
NS_ReadOptionalString(nsIBinaryInputStream* aStream, nsAString& aResult)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nonnull;
|
2001-07-31 23:05:34 +04:00
|
|
|
nsresult rv = aStream->ReadBoolean(&nonnull);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nonnull)
|
2002-11-14 21:16:31 +03:00
|
|
|
rv = aStream->ReadString(aResult);
|
2001-07-31 23:05:34 +04:00
|
|
|
else
|
2002-11-14 21:16:31 +03:00
|
|
|
aResult.Truncate();
|
2001-07-31 23:05:34 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2005-10-20 20:39:24 +04:00
|
|
|
#endif
|
2001-07-31 23:05:34 +04:00
|
|
|
|
1999-11-16 22:12:41 +03:00
|
|
|
%}
|