美文网首页
netty字节美化

netty字节美化

作者: 不知不怪 | 来源:发表于2023-01-31 18:49 被阅读0次
package com.gzz.study;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;

public class ByteBufStudy {
    public static void main(String[] args) {
        // 创建ByteBuf
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(16, 20);
        System.out.println(ByteBufUtil.prettyHexDump(buffer));

        // 向buffer中写入数据
        buffer.writeBytes(new byte[] { 1, 2, 3, 4 });
        System.out.println(ByteBufUtil.prettyHexDump(buffer));

        buffer.writeInt(5);
        System.out.println(ByteBufUtil.prettyHexDump(buffer));

        buffer.writeIntLE(6);
        System.out.println(ByteBufUtil.prettyHexDump(buffer));

        buffer.writeLong(7);
        System.out.println(ByteBufUtil.prettyHexDump(buffer));
    }
}

         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 01 02 03 04                                     |....            |
+--------+-------------------------------------------------+----------------+
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 01 02 03 04 00 00 00 05                         |........        |
+--------+-------------------------------------------------+----------------+
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 01 02 03 04 00 00 00 05 06 00 00 00             |............    |
+--------+-------------------------------------------------+----------------+
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+

相关文章

网友评论

      本文标题:netty字节美化

      本文链接:https://www.haomeiwen.com/subject/dudbhdtx.html