Exemplo n.º 1
0
size_t
GenericHeader::read(IDataReader &reader)
{
    size_t bufLen = 1024 * 32;
    DataBuffer buf(bufLen, ALIGNMENT);
    size_t numBytesRead = reader.getData(buf.getFree(), bufLen);
    buf.moveFreeToData(numBytesRead);

    if (numBytesRead < 4 /* magic */ + 4 /* size */) {
        throw IllegalHeaderException("Failed to read header info.");
    }
    uint32_t magic = buf.readInt32();
    if (magic != MAGIC) {
        throw IllegalHeaderException("Failed to verify magic bits.");
    }
    uint32_t numBytesTotal = buf.readInt32();
    if (numBytesTotal == 0) {
        throw IllegalHeaderException("Failed to read header size.");
    }
    if (numBytesTotal < getMinSize()) {
        throw IllegalHeaderException("Failed to verify header size.");
    }
    if (numBytesRead < numBytesTotal) {
        LOG(debug, "Read %d of %d header bytes, performing backfill.",
            (uint32_t)numBytesRead, numBytesTotal);
        uint32_t numBytesRemain = numBytesTotal - numBytesRead;
        buf.ensureFree(numBytesRemain);
        LOG(debug, "Reading remaining %d bytes of header.", numBytesRemain);
        numBytesRead += reader.getData(buf.getFree(), numBytesRemain);
        if (numBytesRead != numBytesTotal) {
            throw IllegalHeaderException("Failed to read full header.");
        }
        buf.moveFreeToData(numBytesRemain);
    } else {
        buf.moveDataToFree(numBytesRead - numBytesTotal);
    }

    uint32_t version = buf.readInt32();
    if (version != VERSION) {
        throw IllegalHeaderException("Failed to verify header version.");
    }
    uint32_t numTags = buf.readInt32();
    TagMap tags;
    for (uint32_t i = 0; i < numTags; ++i) {
        Tag tag;
        tag.read(buf);
        tags.insert(TagMap::value_type(tag.getName(), tag));
    }
    _tags.swap(tags);
    return numBytesTotal;
}
Exemplo n.º 2
0
void QFieldDefinitionData::init(TagMap &tagMap, FieldMap &fieldMap, ActionMap &actionMap, QTranslatableSettings &config)
{
    QList<QFieldDefinition> fields;
    QMap<QString, QFieldAction> actions;

    fields = QFieldDefinitionData::readFields(config);
    actions = QFieldDefinitionData::readActions(config);

    foreach(QFieldDefinition def, fields) {
        if (!fieldMap.contains(def.id())) {
            fieldMap.insert(def.id(), def);
            QStringList tags = def.tags();
            foreach(QString tag, tags)
            {
                QSet<QString> taggedFields;
                if (tagMap.contains(tag))
                    taggedFields = tagMap.value(tag);
                taggedFields.insert(def.id());
                tagMap.insert(tag, taggedFields);
            }
        }