1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
---|
2 | * ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is Mozilla Communicator client code, released
|
---|
16 | * March 31, 1998.
|
---|
17 | *
|
---|
18 | * The Initial Developer of the Original Code is
|
---|
19 | * Netscape Communications Corporation.
|
---|
20 | * Portions created by the Initial Developer are Copyright (C) 1998-1999
|
---|
21 | * the Initial Developer. All Rights Reserved.
|
---|
22 | *
|
---|
23 | * Contributor(s):
|
---|
24 | *
|
---|
25 | * Alternatively, the contents of this file may be used under the terms of
|
---|
26 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
27 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
28 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
29 | * of those above. If you wish to allow use of your version of this file only
|
---|
30 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
31 | * use your version of this file under the terms of the MPL, indicate your
|
---|
32 | * decision by deleting the provisions above and replace them with the notice
|
---|
33 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
34 | * the provisions above, a recipient may use your version of this file under
|
---|
35 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
36 | *
|
---|
37 | * ***** END LICENSE BLOCK ***** */
|
---|
38 |
|
---|
39 | #include "nsIInputStream.idl"
|
---|
40 | #include "nsrootidl.idl"
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * This interface allows consumption of primitive data types from a "binary
|
---|
44 | * stream" containing untagged, big-endian binary data, i.e. as produced by an
|
---|
45 | * implementation of nsIBinaryOutputStream. This might be used, for example,
|
---|
46 | * to implement network protocols or to read from architecture-neutral disk
|
---|
47 | * files, i.e. ones that can be read and written by both big-endian and
|
---|
48 | * little-endian platforms.
|
---|
49 | *
|
---|
50 | * @See nsIBinaryOutputStream
|
---|
51 | */
|
---|
52 |
|
---|
53 | [scriptable, uuid(7b456cb0-8772-11d3-90cf-0040056a906e)]
|
---|
54 | interface nsIBinaryInputStream : nsIInputStream {
|
---|
55 | void setInputStream(in nsIInputStream aInputStream);
|
---|
56 |
|
---|
57 | PRBool readBoolean();
|
---|
58 |
|
---|
59 | PRUint8 read8();
|
---|
60 | PRUint16 read16();
|
---|
61 | PRUint32 read32();
|
---|
62 | PRUint64 read64();
|
---|
63 |
|
---|
64 | float readFloat();
|
---|
65 | double readDouble();
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Read a NUL-terminated 8-bit char* string from a binary stream.
|
---|
69 | */
|
---|
70 | ACString readCString();
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Read a NUL-terminated 16-bit PRUnichar* string from a binary stream.
|
---|
74 | */
|
---|
75 | AString readString();
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Read an opaque byte array from a binary stream.
|
---|
79 | */
|
---|
80 | void readBytes(in PRUint32 aLength,
|
---|
81 | [size_is(aLength), retval] out string aString);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Read an opaque byte array from a binary stream, storing the results
|
---|
85 | * as an array of PRUint8s.
|
---|
86 | */
|
---|
87 | void readByteArray(in PRUint32 aLength,
|
---|
88 | [array, size_is(aLength), retval] out PRUint8 aBytes);
|
---|
89 | };
|
---|
90 |
|
---|
91 | %{C++
|
---|
92 |
|
---|
93 | inline nsresult
|
---|
94 | NS_ReadOptionalCString(nsIBinaryInputStream* aStream, nsACString& aResult)
|
---|
95 | {
|
---|
96 | PRBool nonnull;
|
---|
97 | nsresult rv = aStream->ReadBoolean(&nonnull);
|
---|
98 | if (NS_SUCCEEDED(rv)) {
|
---|
99 | if (nonnull)
|
---|
100 | rv = aStream->ReadCString(aResult);
|
---|
101 | else
|
---|
102 | aResult.Truncate();
|
---|
103 | }
|
---|
104 | return rv;
|
---|
105 | }
|
---|
106 |
|
---|
107 | inline nsresult
|
---|
108 | NS_ReadOptionalString(nsIBinaryInputStream* aStream, nsAString& aResult)
|
---|
109 | {
|
---|
110 | PRBool nonnull;
|
---|
111 | nsresult rv = aStream->ReadBoolean(&nonnull);
|
---|
112 | if (NS_SUCCEEDED(rv)) {
|
---|
113 | if (nonnull)
|
---|
114 | rv = aStream->ReadString(aResult);
|
---|
115 | else
|
---|
116 | aResult.Truncate();
|
---|
117 | }
|
---|
118 | return rv;
|
---|
119 | }
|
---|
120 |
|
---|
121 | %}
|
---|