Ejemplo 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);
                }
            }