1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include
"nsISupports.idl"
9 * An interface for access to a buffering stream implementation's underlying
12 * Stream implementations that QueryInterface to nsIStreamBufferAccess must
13 * ensure that all buffers are aligned on the most restrictive type size for
14 * the current architecture (e.g., sizeof(double) for RISCy CPUs). malloc(3)
15 * satisfies this requirement.
17 [scriptable
, builtinclass
, uuid(ac923b72
-ac87
-4892-ac7a
-ca385d429435
)]
18 interface nsIStreamBufferAccess
: nsISupports
21 * Get access to a contiguous, aligned run of bytes in the stream's buffer.
22 * Exactly one successful getBuffer call must occur before a putBuffer call
23 * taking the non-null pointer returned by the successful getBuffer.
25 * The run of bytes are the next bytes (modulo alignment padding) to read
26 * for an input stream, and the next bytes (modulo alignment padding) to
27 * store before (eventually) writing buffered data to an output stream.
28 * There can be space beyond this run of bytes in the buffer for further
29 * accesses before the fill or flush point is reached.
32 * Count of contiguous bytes requested at the address A that satisfies
33 * (A & aAlignMask) == 0 in the buffer, starting from the current stream
34 * position, mapped to a buffer address B. The stream implementation
35 * must pad from B to A by skipping bytes (if input stream) or storing
36 * zero bytes (if output stream).
39 * Bit-mask computed by subtracting 1 from the power-of-two alignment
40 * modulus (e.g., 3 or sizeof(uint32_t)-1 for uint32_t alignment).
43 * The aligned pointer to aLength bytes in the buffer, or null if the
44 * buffer has no room for aLength bytes starting at the next address A
45 * after the current position that satisfies (A & aAlignMask) == 0.
47 [notxpcom
,noscript
] charPtr getBuffer
(in uint32_t aLength
, in uint32_t aAlignMask
);
50 * Relinquish access to the stream's buffer, filling if at end of an input
51 * buffer, flushing if completing an output buffer. After a getBuffer call
52 * that returns non-null, putBuffer must be called.
55 * A non-null pointer returned by getBuffer on the same stream buffer
59 * The same count of contiguous bytes passed to the getBuffer call that
62 [notxpcom
,noscript
] void putBuffer
(in charPtr aBuffer
, in uint32_t aLength
);
65 * Disable and enable buffering on the stream implementing this interface.
66 * DisableBuffering flushes an output stream's buffer, and invalidates an
67 * input stream's buffer.
69 void disableBuffering
();
70 void enableBuffering
();
73 * The underlying, unbuffered input or output stream.
75 readonly attribute nsISupports unbufferedStream
;
81 * These macros get and put a buffer given either an sba parameter that may
82 * point to an object implementing nsIStreamBufferAccess, nsIObjectInputStream,
83 * or nsIObjectOutputStream.
85 #define NS_GET_BUFFER
(sba
,n
,a
) ((sba
)->GetBuffer
(n
, a
))
86 #define NS_PUT_BUFFER
(sba
,p
,n
) ((sba
)->PutBuffer
(p
, n
))