Java Code Examples for skadistats.clarity.model.StringTable#setValueForIndex()

The following examples show how to use skadistats.clarity.model.StringTable#setValueForIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S1StringTableEmitter.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void decodeEntries(StringTable table, ByteString encodedData, int numEntries) {
    BitStream stream = BitStream.createBitStream(encodedData);
    int bitsPerIndex = Util.calcBitsNeededFor(table.getMaxEntries() - 1);
    String[] keyHistory = new String[KEY_HISTORY_SIZE];

    boolean mysteryFlag = stream.readBitFlag();
    int index = -1;
    for (int i = 0; i < numEntries; i++) {
        // read index
        if (stream.readBitFlag()) {
            index++;
        } else {
            index = stream.readUBitInt(bitsPerIndex);
        }

        // read name
        String name = null;
        if (stream.readBitFlag()) {
            if (mysteryFlag && stream.readBitFlag()) {
                throw new ClarityException("mystery_flag assert failed!");
            }
            if (stream.readBitFlag()) {
                int base = i > KEY_HISTORY_SIZE ? i : 0;
                int offs = stream.readUBitInt(5);
                int len = stream.readUBitInt(5);
                String str = keyHistory[(base + offs) & KEY_HISTORY_MASK];
                name = str.substring(0, len) + stream.readString(MAX_NAME_LENGTH);
            } else {
                name = stream.readString(MAX_NAME_LENGTH);
            }
        }
        // read value
        ByteString data = null;
        if (stream.readBitFlag()) {
            int bitLength;
            if (table.getUserDataFixedSize()) {
                bitLength = table.getUserDataSizeBits();
            } else {
                bitLength = stream.readUBitInt(14) * 8;
            }
            byte[] valueBuf = new byte[(bitLength + 7) / 8];
            stream.readBitsIntoByteArray(valueBuf, bitLength);
            data = ZeroCopy.wrap(valueBuf);
        }

        int entryCount = table.getEntryCount();
        if (index < entryCount) {
            // update old entry
            table.setValueForIndex(index, data);
            assert(name == null || Objects.equals(name, table.getNameByIndex(index)));
            name = table.getNameByIndex(index);
        } else if (index == entryCount) {
            // add a new entry
            assert(name != null);
            table.addEntry(name, data);
        } else {
            throw new IllegalStateException("index > entryCount");
        }

        keyHistory[i & KEY_HISTORY_MASK] = name;

        raise(table, index, name, data);
    }
}
 
Example 2
Source File: S2StringTableEmitter.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void decodeEntries(StringTable table, ByteString encodedData, int numEntries) throws IOException {
    BitStream stream = BitStream.createBitStream(encodedData);
    String[] keyHistory = new String[KEY_HISTORY_SIZE];

    int index = -1;
    for (int i = 0; i < numEntries; i++) {
        // read index
        if (stream.readBitFlag()) {
            index++;
        } else {
            index += stream.readVarUInt() + 2;
        }

        // read name
        String name = null;
        if (stream.readBitFlag()) {
            if (stream.readBitFlag()) {
                int base = i > KEY_HISTORY_SIZE ? i : 0;
                int offs = stream.readUBitInt(5);
                int len = stream.readUBitInt(5);
                String str = keyHistory[(base + offs) & KEY_HISTORY_MASK];
                name = str.substring(0, len) + stream.readString(MAX_NAME_LENGTH);
            } else {
                name = stream.readString(MAX_NAME_LENGTH);
            }
        }

        // read value
        ByteString data = null;
        if (stream.readBitFlag()) {
            boolean isCompressed = false;
            int bitLength;
            if (table.getUserDataFixedSize()) {
                bitLength = table.getUserDataSizeBits();
            } else {
                if ((table.getFlags() & 0x1) != 0) {
                    // this is the case for the instancebaseline for console recorded replays
                    isCompressed = stream.readBitFlag();
                }
                bitLength = stream.readUBitInt(17) * 8;
            }

            int byteLength = (bitLength + 7) / 8;
            byte[] valueBuf;
            if (isCompressed) {
                stream.readBitsIntoByteArray(tempBuf, bitLength);
                int byteLengthUncompressed = Snappy.uncompressedLength(tempBuf, 0, byteLength);
                valueBuf = new byte[byteLengthUncompressed];
                Snappy.rawUncompress(tempBuf, 0, byteLength, valueBuf, 0);
            } else {
                valueBuf = new byte[byteLength];
                stream.readBitsIntoByteArray(valueBuf, bitLength);
            }
            data = ZeroCopy.wrap(valueBuf);
        }

        int entryCount = table.getEntryCount();
        if (index < entryCount) {
            // update old entry
            table.setValueForIndex(index, data);
            assert(name == null || Objects.equals(name, table.getNameByIndex(index)));
            name = table.getNameByIndex(index);
        } else if (index == entryCount) {
            // add a new entry
            assert(name != null);
            table.addEntry(name, data);
        } else {
            throw new IllegalStateException("index > entryCount");
        }

        keyHistory[i & KEY_HISTORY_MASK] = name;

        raise(table, index, name, data);
    }
}