Last active
April 29, 2016 09:25
-
-
Save easternHong/33d3f3153dea8e13f61998e7edb9d837 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Message | |
public static class MsgHeader { | |
public MsgHeader() { | |
msgId = -1; | |
} | |
@Index(0) | |
public int msgId; | |
public byte[] toBytes() { | |
try { | |
MessagePack msgpack = new MessagePack(); | |
return msgpack.write(this); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
return null; | |
} | |
} | |
public MsgHeader fromBytes(byte[] bytes) { | |
MsgHeader header = null; | |
try { | |
MessagePack msgPack = new MessagePack(); | |
header = msgPack.read(bytes, MsgHeader.class); | |
switch (header.msgId) { | |
case EFAML_CALL_CANCEL: | |
return msgPack.read(bytes, ClientCall.class); | |
} | |
} catch (Exception e) { | |
} | |
return null; | |
} | |
} | |
@Message // | |
public static class ClientCall extends MsgpackMsg.MsgHeader { | |
public ClientCall() { | |
msgId = MsgpackMsg.EFAML_CALL_CANCEL; | |
} | |
@Index(1) | |
public int time = 0; | |
@Index(2) | |
public String url; | |
} | |
//and this is invoked from native layer | |
public void test(byte[]bytes){ | |
MsgpackMsg.MsgHeader msgHeader = new MsgpackMsg.MsgHeader().fromBytes(bytes); | |
if (msgHeader == null) | |
return; | |
int msgPackId = msgHeader.msgId; | |
try { | |
handle(msgPackId, msgHeader); | |
} catch (Exception e) { | |
Log.ex(e.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment