Message02.java
1.63 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.bsth.socket.protocol;
import com.bsth.util.ConvertUtil;
import org.joda.time.DateTime;
import java.util.ArrayList;
import java.util.List;
/**
* @author Hill
* 实时信息上报
*/
public class Message02 implements IMessageBody {
/**
* byte[6]
* 数据采集时间
*/
private long timestamp;
/**
* 数据体
*/
private List<IMessageBody02> body02List = new ArrayList<>();
/**
* 缓存标志
*/
private boolean cache;
@Override
public void read(byte[] bytes) {
// TODO Auto-generated method stub
int idx = 0;
timestamp = ConvertUtil.bytes2timestamp(bytes, idx); idx += 6;
while (idx < bytes.length - 1) {
IMessageBody02 body02 = Message02Factory.create(bytes[idx] & 0xff, bytes, idx);
body02List.add(body02);
idx += body02.getByteLen();
}
}
@Override
public byte[] write() {
// TODO Auto-generated method stub
return ConvertUtil.timestamp2bytes(timestamp);
}
public long getTimestamp() {
return timestamp;
}
@Override
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public List<IMessageBody02> getBody02List() {
return body02List;
}
public void setBody02List(List<IMessageBody02> body02List) {
this.body02List = body02List;
}
public boolean isCache() {
return cache;
}
public void setCache(boolean cache) {
this.cache = cache;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(" 数据采集时间:").append(new DateTime(timestamp).toString("yyyy-MM-dd HH:mm:ss"));
for (IMessageBody02 body02 : body02List) {
sb.append(body02.toString()).append(" \n");
}
return sb.toString();
}
}