Ejemplo n.º 1
0
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
        {
            IByteBuffer nextHeader = null;

            do
            {
                if (input.ReadableBytes > 1)
                {
                    try
                    {
                        nextHeader = MQParser.Next(input);
                    }
                    catch (Exception ex)
                    {
                        if (ex is MalformedMessageException || ex is IndexOutOfRangeException)
                        {
                            input.ResetReaderIndex();
                            if (nextHeader != null)
                            {
                                nextHeader.Release();
                                nextHeader = null;
                            }
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }

                if (nextHeader != null)
                {
                    input.ReadBytes(nextHeader, nextHeader.Capacity);
                    try
                    {
                        MQMessage header = MQParser.Decode(nextHeader);
                        output.Add(header);
                    }
                    catch (Exception e)
                    {
                        input.ResetReaderIndex();
                        context.Channel.Pipeline.Remove(this);
                        throw e;
                    }
                    finally
                    {
                        nextHeader.Release();
                    }
                }
            }while (input.ReadableBytes > 1 && nextHeader != null);
        }
        protected override void Encode(IChannelHandlerContext context, MQMessage message, IByteBuffer output)
        {
            IByteBuffer buf = MQParser.encode(message);

            output.WriteBytes(buf);
        }