Exemple #1
0
        /// <summary>
        ///		Unpack request/notification message array header.
        /// </summary>
        /// <param name="context">Context information.</param>
        /// <returns>
        ///		<c>true</c>, if the pipeline is finished;
        ///		<c>false</c>, the pipeline is interruppted because extra data is needed.
        /// </returns>
        internal bool UnpackRequestHeader(ServerRequestContext context)
        {
            Contract.Assert(context != null);

            if (context.RootUnpacker == null)
            {
                context.UnpackingBuffer = new ByteArraySegmentStream(context.ReceivedData);
                context.RootUnpacker    = Unpacker.Create(context.UnpackingBuffer, false);
                Interlocked.Increment(ref this._processing);
                context.RenewSessionId();
                if (this._manager.Server.Configuration.ReceiveTimeout != null)
                {
                    context.Timeout += this.OnReceiveTimeout;
                    context.StartWatchTimeout(this._manager.Server.Configuration.ReceiveTimeout.Value);
                }

                if (MsgPackRpcServerProtocolsTrace.ShouldTrace(MsgPackRpcServerProtocolsTrace.NewSession))
                {
                    MsgPackRpcServerProtocolsTrace.TraceEvent(
                        MsgPackRpcServerProtocolsTrace.NewSession,
                        "New session is created. {{ \"SessionID\" : {0} }}",
                        context.SessionId
                        );
                }
            }

            if (!context.ReadFromRootUnpacker())
            {
                MsgPackRpcServerProtocolsTrace.TraceEvent(
                    MsgPackRpcServerProtocolsTrace.NeedRequestHeader,
                    "Array header is needed. {{ \"SessionID\" : {0} }}",
                    context.SessionId
                    );
                return(false);
            }

            if (!context.RootUnpacker.IsArrayHeader)
            {
                this.HandleDeserializationError(context, "Invalid request/notify message stream. Message must be array.", () => context.UnpackingBuffer.ToArray());
                return(true);
            }

            if (context.RootUnpacker.ItemsCount != 3 && context.RootUnpacker.ItemsCount != 4)
            {
                this.HandleDeserializationError(
                    context,
                    String.Format(
                        CultureInfo.CurrentCulture,
                        "Invalid request/notify message stream. Message must be valid size array. Actual size is {0}.",
                        context.RootUnpacker.ItemsCount
                        ),
                    () => context.UnpackingBuffer.ToArray()
                    );
                return(true);
            }

            context.HeaderUnpacker = context.RootUnpacker.ReadSubtree();
            context.NextProcess    = UnpackMessageType;
            return(context.NextProcess(context));
        }