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 |
+--------+-------------------------------------------------+----------------+
网友评论