xpcom/io/nsIBinaryOutputStream.idl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/io/nsIBinaryOutputStream.idl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsIOutputStream.idl"
    1.10 +
    1.11 +/**
    1.12 + * This interface allows writing of primitive data types (integers,
    1.13 + * floating-point values, booleans, etc.) to a stream in a binary, untagged,
    1.14 + * fixed-endianness format.  This might be used, for example, to implement
    1.15 + * network protocols or to produce architecture-neutral binary disk files,
    1.16 + * i.e. ones that can be read and written by both big-endian and little-endian
    1.17 + * platforms.  Output is written in big-endian order (high-order byte first),
    1.18 + * as this is traditional network order.
    1.19 + *
    1.20 + * @See nsIBinaryInputStream
    1.21 + */
    1.22 +
    1.23 +[scriptable, uuid(204ee610-8765-11d3-90cf-0040056a906e)]
    1.24 +interface nsIBinaryOutputStream : nsIOutputStream {
    1.25 +    void setOutputStream(in nsIOutputStream aOutputStream);
    1.26 +    
    1.27 +    /**
    1.28 +     * Write a boolean as an 8-bit char to the stream.
    1.29 +     */
    1.30 +    void writeBoolean(in boolean aBoolean);
    1.31 +
    1.32 +    void write8(in uint8_t aByte);
    1.33 +    void write16(in uint16_t a16);
    1.34 +    void write32(in uint32_t a32);
    1.35 +    void write64(in uint64_t a64);
    1.36 +
    1.37 +    void writeFloat(in float aFloat);
    1.38 +    void writeDouble(in double aDouble);
    1.39 +
    1.40 +    /**
    1.41 +     * Write an 8-bit pascal style string to the stream.
    1.42 +     * 32-bit length field, followed by length 8-bit chars.
    1.43 +     */
    1.44 +    void writeStringZ(in string aString);
    1.45 +
    1.46 +    /**
    1.47 +     * Write a 16-bit pascal style string to the stream.
    1.48 +     * 32-bit length field, followed by length PRUnichars.
    1.49 +     */
    1.50 +    void writeWStringZ(in wstring aString);
    1.51 +
    1.52 +    /**
    1.53 +     * Write an 8-bit pascal style string (UTF8-encoded) to the stream.
    1.54 +     * 32-bit length field, followed by length 8-bit chars.
    1.55 +     */
    1.56 +    void writeUtf8Z(in wstring aString);
    1.57 +
    1.58 +    /**
    1.59 +     * Write an opaque byte array to the stream.
    1.60 +     */
    1.61 +    void writeBytes([size_is(aLength)] in string aString, in uint32_t aLength);
    1.62 +
    1.63 +    /**
    1.64 +     * Write an opaque byte array to the stream.
    1.65 +     */
    1.66 +    void writeByteArray([array, size_is(aLength)] in uint8_t aBytes,
    1.67 +                        in uint32_t aLength);
    1.68 +
    1.69 +};
    1.70 +
    1.71 +%{C++
    1.72 +
    1.73 +inline nsresult
    1.74 +NS_WriteOptionalStringZ(nsIBinaryOutputStream* aStream, const char* aString)
    1.75 +{
    1.76 +    bool nonnull = (aString != nullptr);
    1.77 +    nsresult rv = aStream->WriteBoolean(nonnull);
    1.78 +    if (NS_SUCCEEDED(rv) && nonnull)
    1.79 +        rv = aStream->WriteStringZ(aString);
    1.80 +    return rv;
    1.81 +}
    1.82 +
    1.83 +inline nsresult
    1.84 +NS_WriteOptionalWStringZ(nsIBinaryOutputStream* aStream, const char16_t* aString)
    1.85 +{
    1.86 +    bool nonnull = (aString != nullptr);
    1.87 +    nsresult rv = aStream->WriteBoolean(nonnull);
    1.88 +    if (NS_SUCCEEDED(rv) && nonnull)
    1.89 +        rv = aStream->WriteWStringZ(aString);
    1.90 +    return rv;
    1.91 +}
    1.92 +
    1.93 +%}

mercurial