use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.
the class AbsContent method parse.
public static AbsContent parse(byte[] data) throws IOException {
BserValues reader = new BserValues(BserParser.deserialize(new DataInput(data)));
AbsContentContainer container;
// Is New Layout
if (reader.getBool(32, false)) {
container = AbsContentContainer.loadContainer(reader.getBytes(33));
} else {
throw new RuntimeException("Unsupported obsolete format");
}
return convertData(container);
}
use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.
the class AbsContentContainer method loadContainer.
public static AbsContentContainer loadContainer(byte[] data) throws IOException {
BserValues values = new BserValues(BserParser.deserialize(new DataInput(data)));
int type = values.getInt(1);
byte[] content = values.getBytes(2);
if (type == TYPE_LOCAL) {
return new ContentLocalContainer(AbsLocalContent.loadContainer(content));
} else if (type == TYPE_REMOTE) {
return new ContentRemoteContainer(ApiMessage.fromBytes(content));
} else {
throw new IOException("Unknown type");
}
}
use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.
the class ContactsSyncActor method preStart.
@Override
public void preStart() {
super.preStart();
if (ENABLE_LOG) {
Log.d(TAG, "Loading contacts ids from storage...");
}
byte[] data = preferences().getBytes("contact_list");
if (data != null) {
try {
DataInput dataInput = new DataInput(data, 0, data.length);
int count = dataInput.readInt();
for (int i = 0; i < count; i++) {
int uid = dataInput.readInt();
if (!contacts.contains(uid)) {
contacts.add(uid);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
notifyState();
self().send(new PerformSync());
}
use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.
the class ManagedConnection method onRawReceived.
private synchronized void onRawReceived(byte[] data) {
if (isClosed) {
return;
}
try {
DataInput dataInput = new DataInput(data);
int packageIndex = dataInput.readInt();
if (receivedPackages != packageIndex) {
Log.w(TAG, "Invalid package index. Expected: " + receivedPackages + ", got: " + packageIndex);
throw new IOException("Invalid package index. Expected: " + receivedPackages + ", got: " + packageIndex);
}
receivedPackages++;
int header = dataInput.readByte();
int dataLength = dataInput.readInt();
byte[] content = dataInput.readBytes(dataLength);
int crc32 = dataInput.readInt();
CRC32_ENGINE.reset();
CRC32_ENGINE.update(content);
if (((int) CRC32_ENGINE.getValue()) != crc32) {
Log.w(TAG, "Incorrect CRC32");
throw new IOException("Incorrect CRC32");
}
// Log.w(TAG, "Received package: " + header);
if (header == HEADER_HANDSHAKE_RESPONSE) {
if (isHandshakePerformed) {
throw new IOException("Double Handshake");
}
onHandshakePackage(content);
} else {
if (!isHandshakePerformed) {
throw new IOException("Package before Handshake");
}
if (header == HEADER_PROTO) {
onProtoPackage(content);
sendAckPackage(packageIndex);
} else if (header == HEADER_PING) {
onPingPackage(content);
} else if (header == HEADER_PONG) {
onPongPackage(content);
} else if (header == HEADER_DROP) {
onDropPackage(content);
} else if (header == HEADER_ACK) {
onAckPackage(content);
} else {
Log.w(TAG, "Received unknown package #" + header);
}
}
} catch (IOException e) {
Log.e(TAG, e);
close();
}
// Log.w(TAG, "onRawReceived:end");
}
use of im.actor.runtime.bser.DataInput in project actor-platform by actorapp.
the class ManagedConnection method onPongPackage.
private synchronized void onPongPackage(byte[] data) throws IOException {
DataInput dataInput = new DataInput(data);
int size = dataInput.readInt();
if (size != 8) {
Log.w(TAG, "Received incorrect pong");
throw new IOException("Incorrect pong payload size");
}
long pingId = dataInput.readLong();
// Log.d(TAG, "Received pong #" + pingId + "...");
CommonTimer timeoutTask = schedulledPings.remove(pingId);
if (timeoutTask == null) {
return;
}
timeoutTask.cancel();
refreshTimeouts();
}
Aggregations