public class TsRpcHead {
public static final int HEAD_SIZE = 40;
private int length;
private short flag;
private short type;
private int sequence;
private int source;
private int destination;
private int checksum;
private int attach_id1;
private int attach_id2;
private int attach_id3;
private int attach_id4;
}
body
idl生成的协议类。
演示样例
序列化(encode)
byte[] data = new TbaUtil<ServiceInfo>().Serialize(clazz, 1024);
String msg = new String(data, "ISO8859-1");
反序列化(decode)
ServiceInfo clazz = new TbaUtil<ServiceInfo>().Deserialize(msg.getBytes("ISO8859-1"), ServiceInfo.class);
网络传输(发送)字节序列化(encode)
void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof ClientPasswordLoginReq) {
log.info("ClientPasswordLoginReq: {}", JSON.toJSONString(msg, true));
ClientPasswordLoginReq entity = (ClientPasswordLoginReq) msg;
//todo
ClientLoginRes body = new ClientLoginRes();
body.error_code = 0;
body.error_text = "OK";
body.session_ticket = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW";
TsRpcHead head = new TsRpcHead(RpcEventType.MT_CLIENT_LOGIN_RES);
ctx.write(new TsEvent(head, body, 1024));
ctx.flush();
}
...
}