Exemplo n.º 1
0
            protected override object Decode(ChannelHandlerContext ctx, Org.Jboss.Netty.Channel.Channel
                                             channel, ChannelBuffer buf)
            {
                if (buf.ReadableBytes() < 4)
                {
                    return(null);
                }
                buf.MarkReaderIndex();
                byte[] fragmentHeader = new byte[4];
                buf.ReadBytes(fragmentHeader);
                int  length = XDR.FragmentSize(fragmentHeader);
                bool isLast = XDR.IsLastFragment(fragmentHeader);

                if (buf.ReadableBytes() < length)
                {
                    buf.ResetReaderIndex();
                    return(null);
                }
                ChannelBuffer newFragment = buf.ReadSlice(length);

                if (currentFrame == null)
                {
                    currentFrame = newFragment;
                }
                else
                {
                    currentFrame = ChannelBuffers.WrappedBuffer(currentFrame, newFragment);
                }
                if (isLast)
                {
                    ChannelBuffer completeFrame = currentFrame;
                    currentFrame = null;
                    return(completeFrame);
                }
                else
                {
                    return(null);
                }
            }
Exemplo n.º 2
0
            public String ReadRaw(ChannelBuffer buf, byte separator)
            {
                int count = buf.BytesBefore(separator);

                if (count < 0)
                {
                    return null;
                }
                byte[] data = new byte[count];

                buf.ReadBytes(data);
                buf.ReadByte(); // get rid of separator

                int length = data.Length;

                for (int i = 0; i < length; i++)
                {
                    if (data[i] == '\\')
                    {
                        if (i + 1 < length)
                        {
                            byte b = data[i + 1];

                            if (b == 't')
                            {
                                data[i] = (byte) '\t';
                            }
                            else if (b == 'r')
                            {
                                data[i] = (byte) '\r';
                            }
                            else if (b == 'n')
                            {
                                data[i] = (byte) '\n';
                            }
                            else
                            {
                                data[i] = b;
                            }

                            Array.Copy(data, i + 2, data, i + 1, length - i - 2);
                            length--;
                        }
                    }
                }

                return Encoding.UTF8.GetString(data, 0, length);
            }
Exemplo n.º 3
0
            public String Read(ChannelBuffer buf, byte separator)
            {
                int count = buf.BytesBefore(separator);

                if (count < 0)
                {
                    return null;
                }
                byte[] data = new byte[count];

                buf.ReadBytes(data);
                buf.ReadByte(); // get rid of separator

                return Encoding.UTF8.GetString(data);
            }