DecoderData.java
7.74 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package com.glsx.pushsdk.common;
import java.util.ArrayList;
import java.util.List;
import com.glsx.pushsdk.model.Entry;
import com.glsx.pushsdk.model.ForceExitEntry;
import com.glsx.pushsdk.model.ForceOffLineData;
import com.glsx.pushsdk.model.GetOffLineContentItem;
import com.glsx.pushsdk.model.GetOffLineIdItem;
import com.glsx.pushsdk.model.GetOfflLineContentDataResult;
import com.glsx.pushsdk.model.GetOfflLineDataResult;
import com.glsx.pushsdk.model.LoginResult;
import com.glsx.pushsdk.model.SdkVersionResult;
import com.glsx.pushsdk.model.proto.MsgClient;
import com.google.protobuf.InvalidProtocolBufferException;
/**
* 解析服务器返回业务数据
*
* @author YFZX-yulg
*/
public class DecoderData {
/**
* 获取返回的登录数据
*
* @param bytes
* @return
* @throws InvalidProtocolBufferException
*/
public static LoginResult getLoginResult(byte[] bytes) {
LoginResult mLoginResult = new LoginResult();
try {
MsgClient.ClientLoginRsp loginRsp = MsgClient.ClientLoginRsp
.parseFrom(bytes);
mLoginResult.setCode(loginRsp.getNRetCode());
mLoginResult.setErrMessage(loginRsp.getChErrDesc().toStringUtf8());
mLoginResult.setGlsxkey(loginRsp.getChGlsxKey().toStringUtf8());
mLoginResult.setSdkVersion(loginRsp.getChSdkVno().toStringUtf8());
} catch (InvalidProtocolBufferException e) {
}
return mLoginResult;
}
/**
* 心跳包回调数据
*
* @param bytes
* @return
*/
public static Entry getHearBeat(byte[] bytes) {
Entry mEntry = new Entry();
try {
MsgClient.ClientHeartBeatRsp heartBeatRsp = MsgClient.ClientHeartBeatRsp
.parseFrom(bytes);
mEntry.setCode(heartBeatRsp.getNRetCode());
mEntry.setErrMessage(heartBeatRsp.getChErrDesc().toStringUtf8());
} catch (InvalidProtocolBufferException e) {
}
return mEntry;
}
/**
* 获取离线回调数据
*
* @param bytes
* @return
*/
public static GetOfflLineDataResult getOffLineData(byte[] bytes) {
GetOfflLineDataResult mEntry = new GetOfflLineDataResult();
try {
MsgClient.ClientGetOfflienMsgRsp getOffLineMsgRsp = MsgClient.ClientGetOfflienMsgRsp
.parseFrom(bytes);
mEntry.setCode(getOffLineMsgRsp.getNRetCode());
mEntry.setErrMessage(getOffLineMsgRsp.getChErrDesc().toStringUtf8());
mEntry.setCount(getOffLineMsgRsp.getMsgIdsCount());
List<GetOffLineIdItem> mGetOffLineIdItem = new ArrayList<GetOffLineIdItem>();
for (int i = 0; i < getOffLineMsgRsp.getMsgIdsList().size(); i++) {
GetOffLineIdItem item = new GetOffLineIdItem();
item.setMsgId(getOffLineMsgRsp.getMsgIdsList().get(i)
.getChMsgId().toStringUtf8());
mGetOffLineIdItem.add(item);
}
mEntry.setmListMsgId(mGetOffLineIdItem);
} catch (InvalidProtocolBufferException e) {
}
return mEntry;
}
/**
* 根据离线ID获取离线内容回调数据
*
* @param bytes
* @return
*/
public static GetOfflLineContentDataResult getOffLineContextData(
byte[] bytes) {
GetOfflLineContentDataResult mEntry = new GetOfflLineContentDataResult();
try {
MsgClient.ClientGetMsgContextByMsgIdsRsp rsp = MsgClient.ClientGetMsgContextByMsgIdsRsp
.parseFrom(bytes);
mEntry.setCode(rsp.getNRetCode());
mEntry.setErrMessage(rsp.getChErrDesc().toStringUtf8());
if (rsp.getOMsgContextList() != null
&& rsp.getOMsgContextList().size() > 0) {
List<GetOffLineContentItem> mList = new ArrayList<GetOffLineContentItem>();
for (int i = 0; i < rsp.getOMsgContextList().size(); i++) {
GetOffLineContentItem item = new GetOffLineContentItem();
item.setMsgId(rsp.getOMsgContextList().get(i).getChMsgId()
.toStringUtf8());
item.setMsgContext(rsp.getOMsgContextList().get(i)
.getChContext().toStringUtf8());
item.setMsgTitle(rsp.getOMsgContextList().get(i)
.getChTitle().toStringUtf8());
item.setMsgType(rsp.getOMsgContextList().get(i).getNType());
item.setMsgCreateTime(rsp.getOMsgContextList().get(i)
.getChMsgTime().toStringUtf8());
item.setMsgAttribute(rsp.getOMsgContextList().get(i).getChAttribute().toStringUtf8());
mList.add(item);
}
mEntry.setmList(mList);
}
} catch (InvalidProtocolBufferException e) {
}
return mEntry;
}
/**
* 服务器推送消息
*
* @param bytes
* @return
*/
public static GetOffLineContentItem getSeviceToClientMsg(byte[] bytes) {
GetOffLineContentItem mEntry = new GetOffLineContentItem();
try {
MsgClient.NotifyMsgToClientReq rsp = MsgClient.NotifyMsgToClientReq
.parseFrom(bytes);
mEntry.setMsgId(rsp.getChMsgId().toStringUtf8());
mEntry.setMsgContext(rsp.getChContext().toStringUtf8());
mEntry.setMsgTitle(rsp.getChTitle().toStringUtf8());
mEntry.setMsgType(rsp.getNType());
mEntry.setMsgCreateTime(rsp.getChMsgTime().toStringUtf8());
mEntry.setMsgAttribute(rsp.getChAttribute().toStringUtf8());
} catch (InvalidProtocolBufferException e) {
}
return mEntry;
}
/**
* 强制退出数据
*
* @param bytes
* @return
*/
public static ForceOffLineData getForceOffLineData(byte[] bytes) {
ForceOffLineData mEntry = new ForceOffLineData();
try {
MsgClient.ForceOfflineToClientReq rsp = MsgClient.ForceOfflineToClientReq
.parseFrom(bytes);
mEntry.setChRstCode(rsp.getChRstCode());
mEntry.setChGlsxKey(rsp.getChGlsxKey().toStringUtf8());
} catch (InvalidProtocolBufferException e) {
}
return mEntry;
}
/**
* 心跳包回调数据
*
* @param bytes
* @return
*/
public static SdkVersionResult getSdkVersionData(byte[] bytes) {
SdkVersionResult mEntry = new SdkVersionResult();
try {
MsgClient.ClientGetSdkVersionRsp rsp = MsgClient.ClientGetSdkVersionRsp
.parseFrom(bytes);
mEntry.setCode(rsp.getNRetCode());
mEntry.setErrMessage(rsp.getChErrDesc().toStringUtf8());
mEntry.setChAddr(rsp.getChAddr().toStringUtf8());
mEntry.setChVerNo(rsp.getChVerNo().toStringUtf8());
mEntry.setnForce(rsp.getNForce());
mEntry.setnType(rsp.getNType());
mEntry.setChDescr(rsp.getChDescr().toStringUtf8());
} catch (InvalidProtocolBufferException e) {
}
return mEntry;
}
/**
* 解析服务器强制退出请求
*
* @param bytes
* @return
*/
public static ForceExitEntry getForceExitLogin(byte[] bytes) {
// TODO Auto-generated method stub
ForceExitEntry mEntry = new ForceExitEntry();
try {
MsgClient.ForceOfflineToClientReq req = MsgClient.ForceOfflineToClientReq.parseFrom(bytes);
mEntry.setChGlsxKey(req.getChGlsxKey().toStringUtf8());
mEntry.setChRstCode(req.getChRstCode());
} catch (InvalidProtocolBufferException e) {
// TODO: handle exception
}
return mEntry;
}
}