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
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/
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
15 * The Original Code is Mozilla FastLoad code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
23 * Brendan Eich <brendan@mozilla.org> (original author)
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.
37 * ***** END LICENSE BLOCK ***** */
39 #include
"nsIBinaryOutputStream.idl"
40 #include
"nsrootidl.idl"
43 * @See nsIObjectInputStream
44 * @See nsIBinaryOutputStream
47 [scriptable
, uuid(92c898ac
-5fde
-4b99
-87b3
-5d486422094b
)]
48 interface nsIObjectOutputStream
: nsIBinaryOutputStream
51 * Write the object whose "root" or XPCOM-identity nsISupports is aObject.
52 * The cause for writing this object is a strong or weak reference, so the
53 * aIsStrongRef argument must tell which kind of pointer is being followed
54 * here during serialization.
56 * If the object has only one strong reference in the serialization and no
57 * weak refs, use writeSingleRefObject. This is a valuable optimization:
58 * it saves space in the stream, and cycles on both ends of the process.
60 * If the reference being serialized is a pointer to an interface not on
61 * the primary inheritance chain ending in the root nsISupports, you must
62 * call writeCompoundObject instead of this method.
64 void writeObject
(in nsISupports aObject
, in PRBool aIsStrongRef
);
67 * Write an object referenced singly and strongly via its root nsISupports
68 * or a subclass of its root nsISupports. There must not be other refs to
69 * aObject in memory, or in the serialization.
71 void writeSingleRefObject
(in nsISupports aObject
);
74 * Write the object referenced by an interface pointer at aObject that
75 * inherits from a non-primary nsISupports, i.e., a reference to one of
76 * the multiply inherited interfaces derived from an nsISupports other
77 * than the root or XPCOM-identity nsISupports; or a reference to an
78 * inner object in the case of true XPCOM aggregation. aIID identifies
81 void writeCompoundObject
(in nsISupports aObject
,
83 in PRBool aIsStrongRef
);
85 void writeID
(in nsIDRef aID
);
88 * Optimized serialization support -- see nsIStreamBufferAccess.idl.
90 [notxpcom
] charPtr getBuffer
(in PRUint32 aLength
, in PRUint32 aAlignMask
);
91 [notxpcom
] void putBuffer
(in charPtr aBuffer
, in PRUint32 aLength
);
97 NS_WriteOptionalObject
(nsIObjectOutputStream
* aStream
, nsISupports
* aObject
,
100 PRBool nonnull
= (aObject
!= nsnull
);
101 nsresult rv
= aStream
->WriteBoolean
(nonnull
);
102 if
(NS_SUCCEEDED
(rv
) && nonnull
)
103 rv
= aStream
->WriteObject
(aObject
, aIsStrongRef
);
108 NS_WriteOptionalSingleRefObject
(nsIObjectOutputStream
* aStream
,
109 nsISupports
* aObject
)
111 PRBool nonnull
= (aObject
!= nsnull
);
112 nsresult rv
= aStream
->WriteBoolean
(nonnull
);
113 if
(NS_SUCCEEDED
(rv
) && nonnull
)
114 rv
= aStream
->WriteSingleRefObject
(aObject
);
119 NS_WriteOptionalCompoundObject
(nsIObjectOutputStream
* aStream
,
120 nsISupports
* aObject
,
124 PRBool nonnull
= (aObject
!= nsnull
);
125 nsresult rv
= aStream
->WriteBoolean
(nonnull
);
126 if
(NS_SUCCEEDED
(rv
) && nonnull
)
127 rv
= aStream
->WriteCompoundObject
(aObject
, aIID
, aIsStrongRef
);