xpcom/io/nsIBinaryInputStream.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsIInputStream.idl"
michael@0 7
michael@0 8 /**
michael@0 9 * This interface allows consumption of primitive data types from a "binary
michael@0 10 * stream" containing untagged, big-endian binary data, i.e. as produced by an
michael@0 11 * implementation of nsIBinaryOutputStream. This might be used, for example,
michael@0 12 * to implement network protocols or to read from architecture-neutral disk
michael@0 13 * files, i.e. ones that can be read and written by both big-endian and
michael@0 14 * little-endian platforms.
michael@0 15 *
michael@0 16 * @See nsIBinaryOutputStream
michael@0 17 */
michael@0 18
michael@0 19 [scriptable, uuid(42084755-fedc-4310-831c-4f43e7b42e20)]
michael@0 20 interface nsIBinaryInputStream : nsIInputStream {
michael@0 21 void setInputStream(in nsIInputStream aInputStream);
michael@0 22
michael@0 23 /**
michael@0 24 * Read 8-bits from the stream.
michael@0 25 *
michael@0 26 * @return that byte to be treated as a boolean.
michael@0 27 */
michael@0 28 boolean readBoolean();
michael@0 29
michael@0 30 uint8_t read8();
michael@0 31 uint16_t read16();
michael@0 32 uint32_t read32();
michael@0 33 uint64_t read64();
michael@0 34
michael@0 35 float readFloat();
michael@0 36 double readDouble();
michael@0 37
michael@0 38 /**
michael@0 39 * Read an 8-bit pascal style string from the stream.
michael@0 40 * 32-bit length field, followed by length 8-bit chars.
michael@0 41 */
michael@0 42 ACString readCString();
michael@0 43
michael@0 44 /**
michael@0 45 * Read an 16-bit pascal style string from the stream.
michael@0 46 * 32-bit length field, followed by length PRUnichars.
michael@0 47 */
michael@0 48 AString readString();
michael@0 49
michael@0 50 /**
michael@0 51 * Read an opaque byte array from the stream.
michael@0 52 *
michael@0 53 * @param aLength the number of bytes that must be read.
michael@0 54 *
michael@0 55 * @throws NS_ERROR_FAILURE if it can't read aLength bytes
michael@0 56 */
michael@0 57 void readBytes(in uint32_t aLength,
michael@0 58 [size_is(aLength), retval] out string aString);
michael@0 59
michael@0 60 /**
michael@0 61 * Read an opaque byte array from the stream, storing the results
michael@0 62 * as an array of PRUint8s.
michael@0 63 *
michael@0 64 * @param aLength the number of bytes that must be read.
michael@0 65 *
michael@0 66 * @throws NS_ERROR_FAILURE if it can't read aLength bytes
michael@0 67 */
michael@0 68 void readByteArray(in uint32_t aLength,
michael@0 69 [array, size_is(aLength), retval] out uint8_t aBytes);
michael@0 70
michael@0 71 /**
michael@0 72 * Read opaque bytes from the stream, storing the results in an ArrayBuffer.
michael@0 73 *
michael@0 74 * @param aLength the number of bytes that must be read
michael@0 75 * @param aArrayBuffer the arraybuffer in which to store the results
michael@0 76 * Note: passing view.buffer, where view is an ArrayBufferView of an
michael@0 77 * ArrayBuffer, is not valid unless view.byteOffset == 0.
michael@0 78 *
michael@0 79 * @throws NS_ERROR_FAILURE if it can't read aLength bytes
michael@0 80 */
michael@0 81 [implicit_jscontext]
michael@0 82 void readArrayBuffer(in uint32_t aLength, in jsval aArrayBuffer);
michael@0 83 };
michael@0 84
michael@0 85 %{C++
michael@0 86
michael@0 87 #ifdef MOZILLA_INTERNAL_API
michael@0 88 #include "nsString.h"
michael@0 89
michael@0 90 inline nsresult
michael@0 91 NS_ReadOptionalCString(nsIBinaryInputStream* aStream, nsACString& aResult)
michael@0 92 {
michael@0 93 bool nonnull;
michael@0 94 nsresult rv = aStream->ReadBoolean(&nonnull);
michael@0 95 if (NS_SUCCEEDED(rv)) {
michael@0 96 if (nonnull)
michael@0 97 rv = aStream->ReadCString(aResult);
michael@0 98 else
michael@0 99 aResult.Truncate();
michael@0 100 }
michael@0 101 return rv;
michael@0 102 }
michael@0 103
michael@0 104 inline nsresult
michael@0 105 NS_ReadOptionalString(nsIBinaryInputStream* aStream, nsAString& aResult)
michael@0 106 {
michael@0 107 bool nonnull;
michael@0 108 nsresult rv = aStream->ReadBoolean(&nonnull);
michael@0 109 if (NS_SUCCEEDED(rv)) {
michael@0 110 if (nonnull)
michael@0 111 rv = aStream->ReadString(aResult);
michael@0 112 else
michael@0 113 aResult.Truncate();
michael@0 114 }
michael@0 115 return rv;
michael@0 116 }
michael@0 117 #endif
michael@0 118
michael@0 119 %}

mercurial