RawMessage.java
1.54 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
package com.ys.yslibrary.bean;
import android.text.TextUtils;
import java.nio.ByteBuffer;
/**
* 交互消息原始数据
*/
public class RawMessage {
private static int sMsgIDStore = 0;
public enum MsgType {
TEXT, Voice
}
public enum FromType {
USER, AIUI
}
public long msgID;
private int msgVersion;
public long responseTime;
public FromType fromType;
public MsgType msgType;
public String cacheContent;
public byte[] msgData;
public RawMessage(FromType fromType, MsgType msgType, byte[] msgData, String cacheContent
, long responseTime) {
this.msgID = sMsgIDStore++;
this.fromType = fromType;
this.msgType = msgType;
this.msgData = msgData;
this.responseTime = responseTime;
this.msgVersion = 0;
this.cacheContent = cacheContent;
}
public RawMessage(FromType fromType, MsgType msgType, byte[] msgData) {
this(fromType, msgType, msgData, null, 0);
}
public boolean isText() {
return msgType == MsgType.TEXT;
}
public boolean isEmptyContent() {return TextUtils.isEmpty(cacheContent);}
public boolean isFromUser() {
return fromType == FromType.USER;
}
public int version() {
return msgVersion;
}
public void versionUpdate() {
msgVersion++;
}
public int getAudioLen() {
if(msgType == MsgType.Voice){
return Math.round(ByteBuffer.wrap(msgData).getFloat());
} else {
return 0;
}
}
}