Skip to content

Instantly share code, notes, and snippets.

@easternHong
Last active April 29, 2016 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save easternHong/33d3f3153dea8e13f61998e7edb9d837 to your computer and use it in GitHub Desktop.
Save easternHong/33d3f3153dea8e13f61998e7edb9d837 to your computer and use it in GitHub Desktop.
@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