protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output) { IByteBuffer nextHeader = null; do { if (input.ReadableBytes > 1) { try { nextHeader = AMQPParser.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 { AMQPHeader header = AMQPParser.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, AMQPHeader message, IByteBuffer output) { IByteBuffer buf = AMQPParser.Encode(message); output.WriteBytes(buf); }