liusuyi
2024-10-25 91f6e60919b92b7f99a41f2ddeb42df17cd0c487
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolEncoder.java
@@ -12,18 +12,14 @@
public class MessageProtocolEncoder extends MessageToByteEncoder<BaseCommand> {
    @Override
    protected void encode(ChannelHandlerContext ctx, BaseCommand command, ByteBuf out) throws Exception {
        out.writeShort(command.getDataHeader()); // 写入帧头
        out.writeShort(command.getDataLength()); // 写入数据长度
        if(command.getBoxSn() != null) {
            out.writeBytes(command.getBoxSn());
        }// 写入指令编号
        out.writeByte(command.getCmdCode()); // 写入指令编号
        command.encode(out); // 编码具体负载
        // 打印
        if(command.getCmdCode()!=0x02) {
            printHex(out);
        }
    }
    // 打印编码后的字节数组
    private void printHex(ByteBuf out)
    {
        // 打印编码后的字节数组