Search in sources :

Example 1 with ProtoPackage

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();
    }
}
Also used : DataInput(im.actor.runtime.bser.DataInput) ProtoStruct(im.actor.core.network.mtp.entity.ProtoStruct) ProtoPackage(im.actor.core.network.mtp.entity.ProtoPackage) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with ProtoPackage

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();
        }
    }
}
Also used : ProtoStruct(im.actor.core.network.mtp.entity.ProtoStruct) ProtoMessage(im.actor.core.network.mtp.entity.ProtoMessage) ProtoPackage(im.actor.core.network.mtp.entity.ProtoPackage) IOException(java.io.IOException)

Example 3 with ProtoPackage

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();
    }
}
Also used : ProtoStruct(im.actor.core.network.mtp.entity.ProtoStruct) ProtoMessage(im.actor.core.network.mtp.entity.ProtoMessage) IOException(java.io.IOException) ProtoPackage(im.actor.core.network.mtp.entity.ProtoPackage) IOException(java.io.IOException)

Aggregations

ProtoPackage (im.actor.core.network.mtp.entity.ProtoPackage)3 ProtoStruct (im.actor.core.network.mtp.entity.ProtoStruct)3 IOException (java.io.IOException)3 ProtoMessage (im.actor.core.network.mtp.entity.ProtoMessage)2 DataInput (im.actor.runtime.bser.DataInput)1