use of im.actor.core.network.mtp.entity.ProtoPackage in project actor-platform by actorapp.
the class AuthKeyActor method onMessage.
private void onMessage(int connectionId, byte[] data, int offset, int len) {
if (connectionId != this.connectionId) {
Log.d(TAG, "Too old: ignoring");
return;
}
ProtoStruct protoStruct;
try {
DataInput dataInput = new DataInput(data, offset, len);
ProtoPackage protoPackage = new ProtoPackage(dataInput);
if (protoPackage.getAuthId() != 0) {
throw new IOException("AuthId != 0");
}
if (protoPackage.getSessionId() != 0) {
throw new IOException("Session != 0");
}
if (protoPackage.getPayload().getMessageId() != 0) {
throw new IOException("MessageId != 0");
}
protoStruct = ProtoSerializer.readMessagePayload(protoPackage.getPayload().getPayload());
} catch (IOException e) {
e.printStackTrace();
crashConnection();
return;
}
try {
if (currentState == null) {
throw new IOException();
}
currentState.onMessage(protoStruct);
} catch (Exception e) {
e.printStackTrace();
crashConnection();
}
}
use of im.actor.core.network.mtp.entity.ProtoPackage in project actor-platform by actorapp.
the class AuthKeyActor method goToState.
private void goToState(ActorState state) {
currentState = state;
if (connection != null) {
try {
ProtoStruct struct = currentState.sendStartMessage();
byte[] data = new ProtoPackage(0, 0, new ProtoMessage(0, struct.toByteArray())).toByteArray();
connection.post(data, 0, data.length);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of im.actor.core.network.mtp.entity.ProtoPackage in project actor-platform by actorapp.
the class AuthKeyActor method onConnectionStarted.
//
// Message Processing
//
private void onConnectionStarted() {
try {
if (currentState == null) {
throw new IOException();
}
ProtoStruct struct = currentState.sendStartMessage();
byte[] data = new ProtoPackage(0, 0, new ProtoMessage(0, struct.toByteArray())).toByteArray();
connection.post(data, 0, data.length);
} catch (Exception e) {
e.printStackTrace();
crashConnection();
}
}
Aggregations