liusuyi
2025-10-18 0752ef5b8ff0ebdad5538ef32f59f08f0b679cbc
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
27
28
package com.ard.work.component.netty.command.register;
 
import com.ard.work.component.netty.command.BaseCmd;
import io.netty.buffer.ByteBuf;
 
/**
 * 心跳命令
 *
 * @author 刘苏义
 * @date 2024/10/22 16:36
 */
public class HeartbeatCmd extends BaseCmd {
 
    private final long timestamp;
 
    public HeartbeatCmd(long timestamp) {
        setDataHeader((short)0x7479);
        setDataLength((short)0x09);
        setCmdCode((byte)0x02);
        this.timestamp = timestamp;
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeLong(timestamp); // 写入时间戳
    }
}