Exemple #1
0
int ModelTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
            ReadBitstreamToTreeParams& args) {

    const unsigned char* dataAt = data;
    int bytesRead = 0;
    uint16_t numberOfModels = 0;
    int expectedBytesPerModel = ModelItem::expectedBytes();

    if (bytesLeftToRead >= (int)sizeof(numberOfModels)) {
        // read our models in....
        numberOfModels = *(uint16_t*)dataAt;
        dataAt += sizeof(numberOfModels);
        bytesLeftToRead -= (int)sizeof(numberOfModels);
        bytesRead += sizeof(numberOfModels);

        if (bytesLeftToRead >= (int)(numberOfModels * expectedBytesPerModel)) {
            for (uint16_t i = 0; i < numberOfModels; i++) {
                ModelItem tempModel;
                int bytesForThisModel = tempModel.readModelDataFromBuffer(dataAt, bytesLeftToRead, args);
                _myTree->storeModel(tempModel);
                dataAt += bytesForThisModel;
                bytesLeftToRead -= bytesForThisModel;
                bytesRead += bytesForThisModel;
            }
        }
    }

    return bytesRead;
}
int ModelTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
            ReadBitstreamToTreeParams& args) {

    // If we're the root, but this bitstream doesn't support root elements with data, then
    // return without reading any bytes
    if (this == _myTree->getRoot() && args.bitstreamVersion < VERSION_ROOT_ELEMENT_HAS_DATA) {
        qDebug() << "ROOT ELEMENT: no root data for "
                    "bitstreamVersion=" << (int)args.bitstreamVersion << " bytesLeftToRead=" << bytesLeftToRead;
        return 0;
    }

    const unsigned char* dataAt = data;
    int bytesRead = 0;
    uint16_t numberOfModels = 0;
    int expectedBytesPerModel = ModelItem::expectedBytes();

    if (bytesLeftToRead >= (int)sizeof(numberOfModels)) {
        // read our models in....
        numberOfModels = *(uint16_t*)dataAt;
        dataAt += sizeof(numberOfModels);
        bytesLeftToRead -= (int)sizeof(numberOfModels);
        bytesRead += sizeof(numberOfModels);
        
        if (bytesLeftToRead >= (int)(numberOfModels * expectedBytesPerModel)) {
            for (uint16_t i = 0; i < numberOfModels; i++) {
                ModelItem tempModel;
                int bytesForThisModel = tempModel.readModelDataFromBuffer(dataAt, bytesLeftToRead, args);
                _myTree->storeModel(tempModel);
                dataAt += bytesForThisModel;
                bytesLeftToRead -= bytesForThisModel;
                bytesRead += bytesForThisModel;
            }
        }
    }

    return bytesRead;
}