Pu Zhibing
2025-04-09 b8a3a680f3e6720a8329bfaae571b09659aace52
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.ruoyi.dataInterchange.model;
 
import com.fasterxml.jackson.annotation.JsonProperty;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.Data;
 
import java.io.UnsupportedEncodingException;
 
/**
 * 补报车辆静态信息请求
 *
 * @author zhibing.pu
 * @Date 2025/3/3 17:24
 */
@Data
public class DOWNBaseMsgVehicleAdded {
    /**
     * 车牌号码
     */
    @JsonProperty("VEHICLE_NO")
    private String vehicleNo;
    /**
     * 车牌颜色
     */
    @JsonProperty("VEHICLE_COLOR")
    private int vehicleColor;
    /**
     * 子业务类型标识
     */
    @JsonProperty("DATA_TYPE")
    private int dataType;
    /**
     * 后续数据长度
     */
    @JsonProperty("DATA_LENGTH")
    private int dataLength;
    
    
    /**
     * 编码报文
     */
    public byte[] encode() {
        ByteBuf byteBuf = Unpooled.buffer(28);
        byte[] bytes1 = new byte[0];
        try {
            bytes1 = this.getVehicleNo().getBytes("GBK");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < 21; i++) {
            if (i < bytes1.length) {
                byteBuf.writeByte(bytes1[i]);
            } else {
                byteBuf.writeByte(0x00);
            }
        }
        byteBuf.writeByte(this.getVehicleColor());
        byteBuf.writeShort(this.getDataType());
        byteBuf.writeInt(this.getDataLength());
        byte[] bytes = ByteBufUtil.getBytes(byteBuf);
        byteBuf.release();
        return bytes;
    }
}