| | |
| | | package com.ard.tianyu.netty.handler;// MessageProtocolEncoder.java |
| | | |
| | | import com.ard.common.utils.ByteUtils; |
| | | import com.ard.tianyu.netty.command.BaseCmd; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | |
| | | out.getBytes(out.readerIndex(), encodedBytes); // 读取ByteBuf中的字节到字节数组中 |
| | | // log.warn("Encoded message bytes: {}", Arrays.toString(encodedBytes)); |
| | | // 将字节数组转换为十六进制格式 |
| | | StringBuilder hexString = new StringBuilder(); |
| | | for (byte b : encodedBytes) { |
| | | hexString.append(String.format("%02X ", b)); // 将每个字节转换为两位十六进制并加上空格 |
| | | } |
| | | |
| | | log.warn("Encoded message in hex: {}", hexString.toString().trim()); |
| | | String hexString = ByteUtils.bytesToHexWithSpaces(encodedBytes); |
| | | log.warn("Encoded message in hex: {}", hexString); |
| | | } |
| | | } |