Beispiel #1
0
        /// <summary>
        /// Tokenize a bin rpc stream for debugging purposes.
        /// </summary>
        /// <param name="streamReader">The reader which will read the raw stream.</param>
        /// <returns>The stream data in a more human-readable format.</returns>
        public static string Tokenize(HmBinaryStreamReader streamReader)
        {
            int state = 0;

            var outB = new StringBuilder();

            streamReader.ReadBytes(3);
            var packetType = streamReader.ReadByte();

            outB.AppendFormat("Bin 0x{0:X2} ", packetType);
            var contentLength = streamReader.ReadInt32();

            outB.AppendFormat("{0} ", contentLength);

            if (packetType == 0x00 || packetType == 0x40)
            {
                //request
                state = 2;
            }

            if (packetType != 0xff && (packetType | 0x40) == 0x40)
            {
                streamReader.ReadBytes(contentLength);
                contentLength = streamReader.ReadInt32();
                outB.AppendFormat("HEADERS_SKIPPED {0} ", contentLength);
            }

            var expected = (int)streamReader.BytesRead + contentLength;

            if (contentLength == 0)
            {
                return(outB.ToString());
            }
            return(tokenize(streamReader, outB, state, expected, false));
        }
Beispiel #2
0
        /// <summary>
        /// Tokenize a bin rpc stream for debugging purposes.
        /// </summary>
        /// <param name="streamReader">The reader which will read the raw stream.</param>
        /// <returns>The stream data in a more human-readable format.</returns>
        public static string Tokenize(HmBinaryStreamReader streamReader)
        {
            int state = 0;

            var outB = new StringBuilder();
            streamReader.ReadBytes(3);
            var packetType = streamReader.ReadByte();
            outB.AppendFormat("Bin 0x{0:X2} ", packetType);
            var contentLength = streamReader.ReadInt32();
            outB.AppendFormat("{0} ", contentLength);

            if (packetType == 0x00 || packetType == 0x40)
            {
                //request
                state = 2;
            }

            if (packetType != 0xff && (packetType | 0x40) == 0x40)
            {
                streamReader.ReadBytes(contentLength);
                contentLength = streamReader.ReadInt32();
                outB.AppendFormat("HEADERS_SKIPPED {0} ", contentLength);
            }

            var expected = (int)streamReader.BytesRead + contentLength;
            if(contentLength == 0)
            {
                return outB.ToString();
            }
            return tokenize(streamReader, outB, state, expected, false);
        }
Beispiel #3
0
        private bool ReadPacketType()
        {
            var header = _stream.ReadBytes(3);

            if (!Packet.PacketHeader.SequenceEqual(header))
            {
                return(false);
            }

            var packetType = _stream.ReadByte();

            switch (packetType)
            {
            case Packet.ErrorMessage:
                MessageType = MessageType.Error;
                return(true);

            case Packet.ResponseMessage:
                MessageType = MessageType.Response;
                return(true);

            case Packet.RequestMessage:
                MessageType = MessageType.Request;
                return(true);

            case Packet.RequestMessageWithHeaders:
                MessageType      = MessageType.Request;
                _containsHeaders = true;
                return(true);

            case Packet.ResponseMessageWithHeaders:
                MessageType      = MessageType.Response;
                _containsHeaders = true;
                return(true);

            default:
                return(false);
            }
        }