-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMessageInput.java
More file actions
41 lines (34 loc) · 1.01 KB
/
MessageInput.java
File metadata and controls
41 lines (34 loc) · 1.01 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
package MessageInput;
import RedisDataBase.RedisString;
import com.alibaba.fastjson.JSON;
/*
用来处理该RPC框架的统一输入格式
首先需要将获取的Byte转换成MessageInput类型的格式
payload 一定是一个json格式的参数,利用fastJson直接转换成对应的类
*/
public class MessageInput{
private RedisString type;
private RedisString requestId;
private RedisString payload;
public MessageInput(RedisString type, RedisString requestId, RedisString payload) {
this.type = type;
this.requestId = requestId;
this.payload = payload;
}
public RedisString getType() {
return type;
}
public RedisString getRequestId() {
return requestId;
}
// 将payload从json string => clazz
public <T> T getPayload(Class<T> clazz) {
if (payload == null) {
return null;
}
return JSON.parseObject(payload.toString(), clazz);
}
public RedisString getContent(){
return payload;
}
}