Search in sources :

Example 6 with DataOutput

use of im.actor.runtime.bser.DataOutput in project actor-platform by actorapp.

the class ManagedConnection method sendAckPackage.

private synchronized void sendAckPackage(int receivedIndex) throws IOException {
    if (isClosed) {
        return;
    }
    DataOutput ackPackage = new DataOutput();
    ackPackage.writeInt(receivedIndex);
    rawPost(HEADER_ACK, ackPackage.toByteArray());
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput)

Example 7 with DataOutput

use of im.actor.runtime.bser.DataOutput in project actor-platform by actorapp.

the class ManagedConnection method sendPingMessage.

private synchronized void sendPingMessage() {
    if (isClosed) {
        return;
    }
    final long pingId = RANDOM.nextLong();
    DataOutput dataOutput = new DataOutput();
    dataOutput.writeInt(8);
    synchronized (RANDOM) {
        dataOutput.writeLong(pingId);
    }
    CommonTimer pingTimeoutTask = new CommonTimer(new TimeoutRunnable());
    schedulledPings.put(pingId, pingTimeoutTask);
    pingTimeoutTask.schedule(RESPONSE_TIMEOUT);
    // Log.d(TAG, "Performing ping #" + pingId + "... " + pingTimeoutTask);
    rawPost(HEADER_PING, dataOutput.toByteArray());
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) CommonTimer(im.actor.runtime.threading.CommonTimer)

Example 8 with DataOutput

use of im.actor.runtime.bser.DataOutput in project actor-platform by actorapp.

the class RatchetKeySignature method hashForSignature.

public static byte[] hashForSignature(long keyId, String keyAlg, byte[] publicKey) {
    byte[] toSign;
    try {
        DataOutput dataOutput = new DataOutput();
        BserWriter writer = new BserWriter(dataOutput);
        writer.writeLong(1, keyId);
        writer.writeString(2, keyAlg);
        Digest sha256 = Crypto.createSHA256();
        sha256.update(publicKey, 0, publicKey.length);
        byte[] hash = new byte[32];
        sha256.doFinal(hash, 0);
        writer.writeBytes(3, hash);
        toSign = dataOutput.toByteArray();
    } catch (Exception e) {
        // Never happens
        return new byte[0];
    }
    return toSign;
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) Digest(im.actor.runtime.crypto.Digest) BserWriter(im.actor.runtime.bser.BserWriter)

Example 9 with DataOutput

use of im.actor.runtime.bser.DataOutput in project actor-platform by actorapp.

the class AbsContent method serialize.

public static byte[] serialize(AbsContent content) throws IOException {
    DataOutput dataOutput = new DataOutput();
    BserWriter writer = new BserWriter(dataOutput);
    // Mark new layout
    writer.writeBool(32, true);
    // Write content
    writer.writeBytes(33, content.getContentContainer().buildContainer());
    return dataOutput.toByteArray();
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) BserWriter(im.actor.runtime.bser.BserWriter)

Example 10 with DataOutput

use of im.actor.runtime.bser.DataOutput in project actor-platform by actorapp.

the class AbsLocalContent method buildContainer.

public byte[] buildContainer() throws IOException {
    DataOutput res = new DataOutput();
    BserWriter writer = new BserWriter(res);
    if (this instanceof LocalPhoto) {
        writer.writeInt(1, CONTENT_PHOTO);
    } else if (this instanceof LocalVideo) {
        writer.writeInt(1, CONTENT_VIDEO);
    } else if (this instanceof LocalDocument) {
        writer.writeInt(1, CONTENT_DOC);
    } else if (this instanceof LocalVoice) {
        writer.writeInt(1, CONTENT_VOICE);
    } else if (this instanceof LocalAnimation) {
        writer.writeInt(1, CONTENT_ANIMATION);
    } else {
        throw new IOException("Unknown type");
    }
    writer.writeBytes(2, toByteArray());
    return res.toByteArray();
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) BserWriter(im.actor.runtime.bser.BserWriter) IOException(java.io.IOException)

Aggregations

DataOutput (im.actor.runtime.bser.DataOutput)12 BserWriter (im.actor.runtime.bser.BserWriter)4 IOException (java.io.IOException)3 CommonTimer (im.actor.runtime.threading.CommonTimer)2 EncryptedCBCPackage (im.actor.core.network.mtp.entity.EncryptedCBCPackage)1 EncryptedPackage (im.actor.core.network.mtp.entity.EncryptedPackage)1 Digest (im.actor.runtime.crypto.Digest)1