Esempio n. 1
0
        /// <summary>Reads a value from the buffer.</summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="buffer">The byte buffer.</param>
        /// <param name="encoding">The encoding of the data in the buffer.</param>
        /// <param name="communicator">The communicator, which is mandatory only when reading proxies.</param>
        /// <param name="reader">The <see cref="InputStreamReader{T}"/> that reads the value from the buffer using an
        /// <see cref="InputStream"/>.</param>
        /// <returns>The value read from the buffer.</returns>
        /// <exception name="InvalidDataException">Thrown when <c>reader</c> finds invalid data or <c>reader</c> leaves
        /// unread data in the buffer.</exception>
        public static T Read <T>(
            this ReadOnlyMemory <byte> buffer,
            Encoding encoding,
            Communicator?communicator,
            InputStreamReader <T> reader)
        {
            var istr   = new InputStream(buffer, encoding, communicator);
            T   result = reader(istr);

            istr.CheckEndOfBuffer(skipTaggedParams: false);
            return(result);
        }
Esempio n. 2
0
        /// <summary>Reads the contents of an encapsulation from the buffer.</summary>
        /// <typeparam name="T">The type of the contents.</typeparam>
        /// <param name="buffer">The byte buffer.</param>
        /// <param name="encoding">The encoding of encapsulation header in the buffer.</param>
        /// <param name="communicator">The communicator.</param>
        /// <param name="payloadReader">The <see cref="InputStreamReader{T}"/> that reads the payload of the
        /// encapsulation using an <see cref="InputStream"/>.</param>
        /// <returns>The contents of the encapsulation read from the buffer.</returns>
        /// <exception name="InvalidDataException">Thrown when <c>buffer</c> is not a valid encapsulation or
        /// <c>payloadReader</c> finds invalid data.</exception>
        public static T ReadEncapsulation <T>(
            this ReadOnlyMemory <byte> buffer,
            Encoding encoding,
            Communicator communicator,
            InputStreamReader <T> payloadReader)
        {
            var istr   = new InputStream(buffer, encoding, communicator, startEncapsulation: true);
            T   result = payloadReader(istr);

            istr.CheckEndOfBuffer(skipTaggedParams: true);
            return(result);
        }
Esempio n. 3
0
        /// <summary>Reads a value from the buffer. This value cannot contain classes or exceptions.</summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="buffer">The byte buffer.</param>
        /// <param name="encoding">The encoding of the data in the buffer.</param>
        /// <param name="reader">The <see cref="InputStreamReader{T}"/> that reads the value from the buffer using an
        /// <see cref="InputStream"/>.</param>
        /// <param name="communicator">The communicator (optional).</param>
        /// <param name="connection">The connection (optional).</param>
        /// <param name="proxy">The proxy (optional).</param>
        /// <returns>The value read from the buffer.</returns>
        /// <exception name="InvalidDataException">Thrown when <c>reader</c> finds invalid data or <c>reader</c> leaves
        /// unread data in the buffer.</exception>
        /// <remarks>When reading proxies, communicator, connection or proxy must be non-null.</remarks>
        public static T Read <T>(
            this ReadOnlyMemory <byte> buffer,
            Encoding encoding,
            InputStreamReader <T> reader,
            Communicator?communicator = null,
            Connection?connection     = null,
            IObjectPrx?proxy          = null)
        {
            var istr   = new InputStream(buffer, encoding, communicator, connection, proxy?.IceReference);
            T   result = reader(istr);

            istr.CheckEndOfBuffer(skipTaggedParams: false);
            return(result);
        }
Esempio n. 4
0
        /// <summary>Reads the arguments from a request. The arguments include a stream argument.</summary>
        /// <paramtype name="T">The type of the arguments.</paramtype>
        /// <param name="connection">The current connection.</param>
        /// <param name="reader">The delegate used to read the arguments.</param>
        /// <returns>The request arguments.</returns>
        public T ReadArgs <T>(Connection connection, InputStreamReaderWithStreamable <T> reader)
        {
            if (PayloadCompressionFormat != CompressionFormat.Decompressed)
            {
                DecompressPayload();
            }

            if (SocketStream == null)
            {
                throw new InvalidDataException("no stream data available for operation with stream parameter");
            }

            var istr = new InputStream(Payload.AsReadOnlyMemory(),
                                       Protocol.GetEncoding(),
                                       connection: connection,
                                       startEncapsulation: true);
            T value = reader(istr, SocketStream);

            // Clear the socket stream to ensure it's not disposed with the request frame. It's now the
            // responsibility of the stream parameter object to dispose the socket stream.
            SocketStream = null;
            istr.CheckEndOfBuffer(skipTaggedParams: true);
            return(value);
        }