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());
}
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());
}
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;
}
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();
}
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();
}
Aggregations