liusuyi
2024-10-22 5141265c6214e84d4ef8a48c6cead6c372cc3892
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.ard.tianyu.netty.command;
 
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
 
@Data
@NoArgsConstructor
public class HeartbeatReplyCommand extends BaseCommand {
 
    private long timestamp; // 时间戳
 
    public HeartbeatReplyCommand(long timestamp) {
        this.timestamp = timestamp;
        setDataHeader((short) 0x6A77); // 设置帧头
        setCmdCode((byte) 0x02); // 设置指令编号
        setDataLength((short) (13)); // 数据长度 (指令编号 + 时间戳)
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());
        out.writeShort(getDataLength());
        out.writeByte(getCmdCode());
        out.writeLong(timestamp); // 写入时间戳
    }
}