Ejemplo n.º 1
0
        public void Convert(IMessageReader input, IMessageBuilder output)
        {
            if (!input.Read())
            {
                throw new ProtocolException("Packet Header not recognized.");
            }

            output.BeginMessage(input.MessageType);

            input.Read();
            if (input.ReadState == ReadState.Headers)
            {
                ConvertHeaders(input, output);
                input.Read();
            }

            output.BeginContent();
            if (input.MessageType == MessageType.Request)
            {
                input.Read();
                output.SetMethod(input.StringValue);

                input.Read();
                ConvertArrayContent(input, output);
            }
            else
            {
                while(input.Read() && input.ReadState == ReadState.Body)
                {
                    ConvertValue(input, output);
                }
            }
            output.EndContent();
            output.EndMessage();

            input.Read();
            if (input.ReadState != ReadState.EndOfFile)
            {
                throw new ProtocolException("Expected EndOfFile");
            }
        }
Ejemplo n.º 2
0
        public void Convert(IMessageReader input, IMessageBuilder output)
        {
            if (!input.Read())
            {
                throw new ProtocolException("Packet Header not recognized.");
            }

            output.BeginMessage(input.MessageType);

            input.Read();
            if (input.ReadState == ReadState.Headers)
            {
                ConvertHeaders(input, output);
                input.Read();
            }

            output.BeginContent();
            if (input.MessageType == MessageType.Request)
            {
                input.Read();
                output.SetMethod(input.StringValue);

                input.Read();
                ConvertArrayContent(input, output);
            }
            else
            {
                while (input.Read() && input.ReadState == ReadState.Body)
                {
                    ConvertValue(input, output);
                }
            }
            output.EndContent();
            output.EndMessage();

            input.Read();
            if (input.ReadState != ReadState.EndOfFile)
            {
                throw new ProtocolException("Expected EndOfFile");
            }
        }