Ejemplo n.º 1
0
        protected override void Decode(IChannelHandlerContext context, IRedisMessage message, List <object> output)
        {
            if (message is ArrayHeaderRedisMessage)
            {
                message = this.DecodeRedisArrayHeader((ArrayHeaderRedisMessage)message);
                if (message is null)
                {
                    return;
                }
            }
            else
            {
                ReferenceCountUtil.Retain(message);
            }

            while ((uint)this.depths.Count > 0u)
            {
                AggregateState current = this.depths.Peek();
                current.Children.Add(message);

                // if current aggregation completed, go to parent aggregation.
                if (current.Children.Count == current.Length)
                {
                    message = new ArrayRedisMessage(current.Children);
                    this.depths.Pop();
                }
                else
                {
                    // not aggregated yet. try next time.
                    return;
                }
            }

            output.Add(message);
        }
Ejemplo n.º 2
0
        public void EncodeNestedArray()
        {
            var channel = new EmbeddedChannel(new RedisEncoder());

            var grandChildren = new List <IRedisMessage>
            {
                new FullBulkStringRedisMessage("bar".Buffer()),
                new IntegerRedisMessage(-1234L)
            };

            var children = new List <IRedisMessage>
            {
                new SimpleStringRedisMessage("foo"),
                new ArrayRedisMessage(grandChildren)
            };

            IRedisMessage message = new ArrayRedisMessage(children);

            Assert.True(channel.WriteOutbound(message));

            IByteBuffer written = ReadAll(channel);

            byte[] output   = written.Bytes();
            byte[] expected = "*2\r\n+foo\r\n*2\r\n$3\r\nbar\r\n:-1234\r\n".Bytes();

            Assert.Equal(expected.Length, output.Length);
            Assert.True(output.SequenceEqual(expected));
            written.Release();
        }
Ejemplo n.º 3
0
        public void EncodeSimpleArray()
        {
            var channel = new EmbeddedChannel(new RedisEncoder());

            var         messages = new List <IRedisMessage>();
            IByteBuffer buffer   = "foo".Buffer();

            buffer.Retain();
            messages.Add(new FullBulkStringRedisMessage(buffer));

            buffer = "bar".Buffer();
            buffer.Retain();
            messages.Add(new FullBulkStringRedisMessage(buffer));

            IRedisMessage message = new ArrayRedisMessage(messages);

            Assert.True(channel.WriteOutbound(message));

            IByteBuffer written = ReadAll(channel);

            byte[] output   = written.Bytes();
            byte[] expected = "*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n".Bytes();

            Assert.Equal(expected.Length, output.Length);
            Assert.True(output.SequenceEqual(expected));
            written.Release();
        }
        public void EncodeSimpleArray()
        {
            var children = new List <IRedisMessage>();

            children.Add(new FullBulkStringRedisMessage((IByteBuffer)ByteBufOf("foo").Retain()));
            children.Add(new FullBulkStringRedisMessage((IByteBuffer)ByteBufOf("bar").Retain()));
            var msg = new ArrayRedisMessage(children);

            Assert.True(this.channel.WriteOutbound(msg));

            IByteBuffer written = ReadAll(this.channel);

            Assert.Equal(BytesOf("*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n"), BytesOf(written));
            written.Release();
        }
Ejemplo n.º 5
0
        void Write(IByteBufferAllocator allocator, ArrayRedisMessage message, ICollection <object> output)
        {
            Contract.Requires(allocator != null);
            Contract.Requires(message != null);
            Contract.Requires(output != null);

            this.WriteArrayHeader(allocator, message.IsNull ? default(long?) : message.Children.Count, output);
            if (message.IsNull)
            {
                return;
            }

            foreach (IRedisMessage childMessage in message.Children)
            {
                this.Write(allocator, childMessage, output);
            }
        }
        public void EncodeNestedArray()
        {
            var grandChildren = new List <IRedisMessage>();

            grandChildren.Add(new FullBulkStringRedisMessage(ByteBufOf("bar")));
            grandChildren.Add(new IntegerRedisMessage(-1234L));
            var children = new List <IRedisMessage>();

            children.Add(new SimpleStringRedisMessage("foo"));
            children.Add(new ArrayRedisMessage(grandChildren));
            var msg = new ArrayRedisMessage(children);

            Assert.True(this.channel.WriteOutbound(msg));

            IByteBuffer written = ReadAll(this.channel);

            Assert.Equal(BytesOf("*2\r\n+foo\r\n*2\r\n$3\r\nbar\r\n:-1234\r\n"), BytesOf(written));
            written.Release();
        }