string FormatByteBufferHolder(IChannelHandlerContext ctx, string eventName, IByteBufferHolder msg) { string chStr = ctx.Channel.ToString(); string msgStr = msg.ToString(); IByteBuffer content = msg.Content; int length = content.ReadableBytes; if (length == 0) { var buf = new StringBuilder(chStr.Length + 1 + eventName.Length + 2 + msgStr.Length + 4); buf.Append(chStr).Append(' ').Append(eventName).Append(", ").Append(msgStr).Append(", 0B"); return(buf.ToString()); } else { int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4; var buf = new StringBuilder( chStr.Length + 1 + eventName.Length + 2 + msgStr.Length + 2 + 10 + 1 + 2 + rows * 80); buf.Append(chStr).Append(' ').Append(eventName).Append(": ") .Append(msgStr).Append(", ").Append(length).Append('B').Append('\n'); ByteBufferUtil.AppendPrettyHexDump(buf, content); return(buf.ToString()); } }
private string FormatByteBuffer(IChannelHandlerContext ctx, string eventName, IByteBuffer msg) { string str1 = ctx.Channel.ToString(); int readableBytes = msg.ReadableBytes; if (readableBytes == 0) { StringBuilder stringBuilder = new StringBuilder(str1.Length + 1 + eventName.Length + 4); string str2 = str1; stringBuilder.Append(str2).Append(' ').Append(eventName).Append(": 0B"); return(stringBuilder.ToString()); } int num = readableBytes / 16 + (readableBytes % 15 == 0 ? 0 : 1) + 4; StringBuilder dump = new StringBuilder(str1.Length + 1 + eventName.Length + 2 + 10 + 1 + 2 + num * 80); string str3 = str1; dump.Append(str3).Append(' ').Append(eventName).Append(": ").Append(readableBytes).Append('B').Append('\n'); IByteBuffer buf = msg; ByteBufferUtil.AppendPrettyHexDump(dump, buf); return(dump.ToString()); }