liusuyi
2024-10-25 75902fb9d5b27a440d14308ccca3c3cff32167bb
ard-work/src/main/java/com/ard/tianyu/netty/command/HeartbeatReplyCommand.java
@@ -1,10 +1,15 @@
package com.ard.tianyu.netty.command;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * 心跳回复命令
 *
 * @author 刘苏义
 * @date 2024/10/22 16:36
 */
@Data
@NoArgsConstructor
public class HeartbeatReplyCommand extends BaseCommand {
@@ -12,15 +17,13 @@
    private long timestamp; // 时间戳
    public HeartbeatReplyCommand(long timestamp) {
        this.timestamp = timestamp;
        setDataHeader((short) 0x6A77); // 设置帧头
        setCmdCode((byte) 0x02); // 设置指令编号
        setDataLength((short) (13)); // 数据长度 (指令编号 + 时间戳)
        this.timestamp = timestamp;
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());
        out.writeShort(getDataLength());
        out.writeByte(getCmdCode());
        out.writeLong(timestamp); // 写入时间戳
    }
}