Exemple #1
0
        /// <summary>Creates a new IncomingRequestFrame.</summary>
        /// <param name="protocol">The Ice protocol.</param>
        /// <param name="data">The frame data as an array segment.</param>
        public IncomingRequestFrame(Protocol protocol, ArraySegment <byte> data)
        {
            Data     = data;
            Protocol = protocol;

            var istr = new InputStream(Protocol.GetEncoding(), data);

            Identity     = new Identity(istr);
            Facet        = istr.ReadFacet();
            Operation    = istr.ReadString();
            IsIdempotent = istr.ReadOperationMode() != OperationMode.Normal;
            Context      = istr.ReadContext();
            Payload      = Data.Slice(istr.Pos);
            (int size, Encoding encoding) = istr.ReadEncapsulationHeader();
            if (protocol == Protocol.Ice1 && size + 4 != Payload.Count)
            {
                // The payload holds an encapsulation and the encapsulation must use up the full buffer with ice1.
                // "4" corresponds to fixed-length size with the 1.1 encoding.
                throw new InvalidDataException($"invalid request encapsulation size: {size}");
            }
            else
            {
                // TODO: with ice2, the payload is followed by a context, and the size is not fixed-length.
                // TODO: read the compression status from the encapsulation data
            }
            Encoding = encoding;
        }
Exemple #2
0
        /// <summary>Creates a new IncomingResponse Frame</summary>
        /// <param name="communicator">The communicator to use when initializing the stream.</param>
        /// <param name="payload">The frame data as an array segment.</param>
        public IncomingResponseFrame(Communicator communicator, ArraySegment <byte> payload)
        {
            _communicator = communicator;
            byte replyStatus = payload[0];

            if (replyStatus > 7)
            {
                throw new InvalidDataException(
                          $"received ice1 response frame with unknown reply status `{replyStatus}'");
            }
            ReplyStatus = (ReplyStatus)replyStatus;
            Payload     = payload;
            if (ReplyStatus == ReplyStatus.UserException || ReplyStatus == ReplyStatus.OK)
            {
                int size;
                (size, Encoding) = InputStream.ReadEncapsulationHeader(Ice1Definitions.Encoding, Payload.AsSpan(1));
                if (size + 4 + 1 != Payload.Count) // 4 = size length with 1.1 encoding
                {
                    throw new InvalidDataException($"invalid response encapsulation size: `{size}'");
                }
            }
            else
            {
                Encoding = Ice1Definitions.Encoding;
            }
        }
Exemple #3
0
        /// <summary>Creates a new IncomingResponse Frame</summary>
        /// <param name="communicator">The communicator to use when initializing the stream.</param>
        /// <param name="protocol">The Ice protocol of this frame.</param>
        /// <param name="payload">The frame data as an array segment.</param>
        public IncomingResponseFrame(Communicator communicator, Protocol protocol, ArraySegment <byte> payload)
        {
            _communicator = communicator;
            Protocol      = protocol;
            byte replyStatus = payload[0];

            if (replyStatus > 7)
            {
                throw new InvalidDataException(
                          $"received {Protocol.GetName()} response frame with unknown reply status `{replyStatus}'");
            }
            ReplyStatus = (ReplyStatus)replyStatus;
            Payload     = payload;
            if (ReplyStatus == ReplyStatus.UserException || ReplyStatus == ReplyStatus.OK)
            {
                int size;
                (size, Encoding) = InputStream.ReadEncapsulationHeader(Protocol.GetEncoding(), Payload.AsSpan(1));
                if (Protocol == Protocol.Ice1 && size + 4 + 1 != Payload.Count) // 4 = size length with 1.1 encoding
                {
                    throw new InvalidDataException($"invalid response encapsulation size: `{size}'");
                }
                // TODO: ice2
            }
            else
            {
                Encoding = Protocol.GetEncoding();
            }
        }
Exemple #4
0
        /// <summary>Creates a new IncomingRequestFrame.</summary>
        /// <param name="communicator">The communicator to use when initializing the stream.</param>
        /// <param name="data">The frame data as an array segment.</param>
        public IncomingRequestFrame(Communicator communicator, ArraySegment <byte> data)
        {
            _communicator = communicator;
            Data          = data;
            var istr = new InputStream(communicator, Ice1Definitions.Encoding, data);

            Identity     = new Identity(istr);
            Facet        = istr.ReadFacet();
            Operation    = istr.ReadString();
            IsIdempotent = istr.ReadOperationMode() != OperationMode.Normal;
            Context      = istr.ReadContext();
            Payload      = Data.Slice(istr.Pos);
            (int size, Encoding encoding) = istr.ReadEncapsulationHeader();
            if (size + 4 != Payload.Count)
            {
                throw new InvalidDataException($"invalid request encapsulation size: {size}");
            }
            Encoding = encoding;
        }