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

The following examples show how to use skadistats.clarity.model.StringTable#getEntryCount() . 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: BaseStringTableEmitter.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@OnMessage(Demo.CDemoStringTables.class)
public void onStringTables(Demo.CDemoStringTables packet) {
    for (Demo.CDemoStringTables.table_t tt : packet.getTablesList()) {
        StringTable table = stringTables.byName.get(tt.getTableName());
        if (table == null) {
            continue;
        }
        applyFullStringTables(table, tt);
        for (int i = 0; i < table.getEntryCount(); i++) {
            raise(table, i, table.getNameByIndex(i), table.getValueByIndex(i));
        }
    }
}
 
Example 2
Source File: Main.java    From clarity-examples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void run(String[] args) throws Exception {
    long tStart = System.currentTimeMillis();

    String demoName = args[0];

    SimpleRunner r = new SimpleRunner(new MappedFileSource(demoName)).runWith(this);

    Context ctx = r.getContext();

    File dir = new File(String.format("baselines%s%s", File.separator, ctx.getBuildNumber() == -1 ? "latest" : ctx.getBuildNumber()));
    if (!dir.exists()) {
        dir.mkdirs();
    }

    FieldReader fieldReader = ctx.getEngineType().getNewFieldReader();

    StringTables stringTables = ctx.getProcessor(StringTables.class);
    DTClasses dtClasses = ctx.getProcessor(DTClasses.class);
    StringTable baselines = stringTables.forName("instancebaseline");

    for (int i = 0; i < baselines.getEntryCount(); i++) {
        DTClass dtClass = dtClasses.forClassId(Integer.valueOf(baselines.getNameByIndex(i)));
        String fileName = String.format("%s%s%s.txt", dir.getPath(), File.separator, dtClass.getDtName());
        log.info("writing {}", fileName);
        fieldReader.DEBUG_STREAM = new PrintStream(new FileOutputStream(fileName), true, "UTF-8");
        BitStream bs = BitStream.createBitStream(baselines.getValueByIndex(i));
        try {
            fieldReader.readFields(bs, dtClass, dtClass.getEmptyState(), null, true);
            if (bs.remaining() < 0 || bs.remaining() > 7) {
                log.info("-- OFF: {} remaining", bs.remaining());
            }
        } catch (Exception e) {
            log.info("-- FAIL: {}", e.getMessage());
            e.printStackTrace(fieldReader.DEBUG_STREAM);
        } finally {
        }
    }

    long tMatch = System.currentTimeMillis() - tStart;
    log.info("total time taken: {}s", (tMatch) / 1000.0);
}
 
Example 3
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 4
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);
    }
}