Search in sources :

Example 1 with BserValues

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");
    }
}
Also used : DataInput(im.actor.runtime.bser.DataInput) BserValues(im.actor.runtime.bser.BserValues) IOException(java.io.IOException)

Example 2 with BserValues

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;
    }
}
Also used : DataInput(im.actor.runtime.bser.DataInput) BserValues(im.actor.runtime.bser.BserValues) IOException(java.io.IOException)

Example 3 with BserValues

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;
}
Also used : DataInput(im.actor.runtime.bser.DataInput) ListEngineRecord(im.actor.runtime.storage.ListEngineRecord) BserValues(im.actor.runtime.bser.BserValues) IOException(java.io.IOException)

Example 4 with BserValues

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);
}
Also used : DataInput(im.actor.runtime.bser.DataInput) AbsContentContainer(im.actor.core.entity.content.internal.AbsContentContainer) BserValues(im.actor.runtime.bser.BserValues)

Example 5 with BserValues

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");
    }
}
Also used : DataInput(im.actor.runtime.bser.DataInput) BserValues(im.actor.runtime.bser.BserValues) IOException(java.io.IOException)

Aggregations

BserValues (im.actor.runtime.bser.BserValues)5 DataInput (im.actor.runtime.bser.DataInput)5 IOException (java.io.IOException)4 AbsContentContainer (im.actor.core.entity.content.internal.AbsContentContainer)1 ListEngineRecord (im.actor.runtime.storage.ListEngineRecord)1