public bool TryParseResponse(RedisSocket socket, string textHeader, out byte[][] result)
        {
            int size;

            if (!int.TryParse(textHeader, out size))
            {
                throw new Exception("Invalid length");
            }

            if (size == -1)
            {
                result = new byte[0][];
                return(true);
            }

            result = new byte[size][];
            for (int index = 0; index < size; index++)
            {
                var bHeader = socket.ReadByte();
                var sHeader = socket.ReadLine();
                if (!BulkByteParser.CheckExpetedHeader(bHeader))
                {
                    throw new Exception("Invalid byte array content");
                }

                if (!BulkByteParser.TryParseResponse(socket, sHeader, out result[index]))
                {
                    throw new Exception("Invalid byte array content");
                }
            }

            return(true);
        }
Beispiel #2
0
        private static ulong ReadNextPointer(RedisSocket socket)
        {
            var bHeader = socket.ReadByte();
            var sHeader = socket.ReadLine();

            if (!BulkByteParser.CheckExpetedHeader(bHeader))
            {
                throw new Exception("Invalid pointer content");
            }

            byte[] buffer;
            if (!BulkByteParser.TryParseResponse(socket, sHeader, out buffer))
            {
                throw new Exception("Invalid pointer content");
            }

            var   number = buffer.ToUtf8String();
            ulong result;

            if (ulong.TryParse(number, out result))
            {
            }

            return(result);
        }
        private static void CheckFailState(int byteHeader, string textHeader)
        {
            if (ErrorParser.CheckExpetedHeader(byteHeader))
            {
                string message;
                if (ErrorParser.TryParseResponse(null, textHeader, out message))
                {
                    throw new Exception(message);
                }

                throw new Exception("Unknown error message response");
            }
        }
Beispiel #4
0
        private static byte[][] ReadArrayResult(RedisSocket socket)
        {
            var bHeader = socket.ReadByte();
            var sHeader = socket.ReadLine();

            if (!BulkByteArrayParser.CheckExpetedHeader(bHeader))
            {
                throw new Exception("Invalid data content");
            }

            byte[][] result;
            if (!BulkByteArrayParser.TryParseResponse(socket, sHeader, out result))
            {
                throw new Exception("Invalid data content");
            }

            return(result);
        }
        public T Receive(RedisSocket socket)
        {
            var byteHeader = socket.ReadByte();
            var textHeader = socket.ReadLine();

            CheckFailState(byteHeader, textHeader);
            if (!parser.CheckExpetedHeader(byteHeader))
            {
                ThrowUnknownReplyException(byteHeader, textHeader);
            }

            T result;

            if (!parser.TryParseResponse(socket, textHeader, out result))
            {
                ThrowUnknownReplyException(byteHeader, textHeader);
            }

            return(result);
        }