Beispiel #1
0
        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());
            }
        }
Beispiel #2
0
        private string FormatByteBufferHolder(IChannelHandlerContext ctx, string eventName, IByteBufferHolder msg)
        {
            string      str1          = ctx.Channel.ToString();
            string      str2          = msg.ToString();
            IByteBuffer content       = msg.Content;
            int         readableBytes = content.ReadableBytes;

            if (readableBytes == 0)
            {
                StringBuilder stringBuilder = new StringBuilder(str1.Length + 1 + eventName.Length + 2 + str2.Length + 4);
                string        str3          = str1;
                stringBuilder.Append(str3).Append(' ').Append(eventName).Append(", ").Append(str2).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 + str2.Length + 2 + 10 + 1 + 2 + num * 80);
            string        str4 = str1;

            dump.Append(str4).Append(' ').Append(eventName).Append(": ").Append(str2).Append(", ").Append(readableBytes).Append('B').Append('\n');
            IByteBuffer buf = content;

            ByteBufferUtil.AppendPrettyHexDump(dump, buf);
            return(dump.ToString());
        }
Beispiel #3
0
        /// <summary>
        ///     Generates the default log message of the specified event whose argument is a <see cref="IByteBufferHolder" />.
        /// </summary>
        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();
            }
        }