Search in sources :

Example 1 with HistoryFrame

use of sugar.free.sightparser.applayer.descriptors.history_frames.HistoryFrame in project SightRemote by TebbeUbben.

the class ReadHistoryFramesMessage method parse.

@Override
protected void parse(ByteBuf byteBuf) throws Exception {
    historyFrames = new ArrayList<>();
    byteBuf.shift(2);
    int frameCount = byteBuf.readUInt16LE();
    for (int i = 0; i < frameCount; i++) {
        int length = byteBuf.readUInt16LE();
        short eventType = byteBuf.readShort();
        ByteBuf eventBuf = new ByteBuf(length - 2);
        eventBuf.putBytes(byteBuf.readBytes(length - 2));
        long eventNumber = eventBuf.getUInt32LE(8);
        if (eventNumber > latestEventNumber)
            latestEventNumber = eventNumber;
        Class<? extends HistoryFrame> clazz = HistoryFrame.HISTORY_FRAMES.get(eventType);
        if (clazz != null) {
            HistoryFrame historyFrame = clazz.newInstance();
            historyFrame.parseHeader(eventBuf);
            historyFrame.parse(eventBuf);
            historyFrames.add(historyFrame);
        } else
            Log.d("SightServiceHistory", "UNKNOWN HISTORY FRAME: EVENT TYPE: " + eventType + " CONTENT: " + Hex.toHexString(eventBuf.getBytes()));
    }
}
Also used : ByteBuf(sugar.free.sightparser.pipeline.ByteBuf) HistoryFrame(sugar.free.sightparser.applayer.descriptors.history_frames.HistoryFrame)

Aggregations

HistoryFrame (sugar.free.sightparser.applayer.descriptors.history_frames.HistoryFrame)1 ByteBuf (sugar.free.sightparser.pipeline.ByteBuf)1