use of im.actor.runtime.bser.BserValues in project actor-platform by actorapp.
the class AbsLocalContent method loadContainer.
public static AbsLocalContent 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 == CONTENT_DOC) {
return new LocalDocument(content);
} else if (type == CONTENT_PHOTO) {
return new LocalPhoto(content);
} else if (type == CONTENT_VIDEO) {
return new LocalVideo(content);
} else if (type == CONTENT_VOICE) {
return new LocalVoice(content);
} else if (type == CONTENT_ANIMATION) {
return new LocalAnimation(content);
} else {
throw new IOException("Unknown type");
}
}
use of im.actor.runtime.bser.BserValues in project actor-platform by actorapp.
the class AbsSignal method fromBytes.
public static AbsSignal fromBytes(byte[] data) {
try {
BserValues values = new BserValues(BserParser.deserialize(new DataInput(data, 0, data.length)));
String type = values.getString(1);
AbsSignal res;
if (OfferSignal.TYPE.equals(type)) {
res = new OfferSignal();
} else if (AnswerSignal.TYPE.equals(type)) {
res = new AnswerSignal();
} else if (CandidateSignal.TYPE.equals(type)) {
res = new CandidateSignal();
} else {
throw new IOException("Unknown signal type " + type);
}
res.parse(values);
return res;
} catch (IOException e) {
return null;
}
}
use of im.actor.runtime.bser.BserValues in project actor-platform by actorapp.
the class MemoryListEngine method loadValue.
private T loadValue(long key) {
T res = cache.lookup(key);
if (res != null) {
return res;
}
ListEngineRecord record = storage.loadItem(key);
if (record == null) {
return null;
}
try {
res = creator.createInstance();
res.parse(new BserValues(BserParser.deserialize(new DataInput(record.getData()))));
} catch (IOException e) {
e.printStackTrace();
return null;
}
cache.onObjectLoaded(key, res);
return res;
}
use of im.actor.runtime.bser.BserValues 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.BserValues 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");
}
}
Aggregations