Пример #1
0
bool BinTreeNodeReader::nextTreeInternal(ProtocolTreeNode& node, QDataStream &in)
{
    quint8 b;

    in >> b;
    int size = readListSize(b,in);
    in >> b;
    if (b == 2)
        return false;

    QByteArray tag;
    readString(b, tag, in);

    int attribCount = (size - 2 + size % 2) / 2;
    AttributeList attribs;
    readAttributes(attribs,attribCount,in);

    node.setTag(tag);
    node.setAttributes(attribs);

    if ((size % 2) == 1)
        return true;

    in >> b;
    if (isListTag(b))
    {
        readList(b,node,in);
        return true;
    }

    QByteArray data;
    readString(b,data,in);
    node.setData(data);
    return true;
}
Пример #2
0
std::vector<ProtocolTreeNode*>* BinTreeNodeReader::readList(int token)
{
	int size = readListSize(token);
	std::vector<ProtocolTreeNode*>* list = new std::vector<ProtocolTreeNode*>(size);
	for (int i = 0; i < size; i++)
		(*list)[i] = nextTreeInternal();

	return list;
}
Пример #3
0
void BinTreeNodeReader::readList(qint32 token,ProtocolTreeNode& node,QDataStream& in)
{
    int size = readListSize(token,in);
    for (int i=0; i<size; i++)
    {
        ProtocolTreeNode child;
        nextTreeInternal(child,in);
        node.addChild(child);
    }
}
Пример #4
0
bool BinTreeNodeReader::nextTreeInternal(ProtocolTreeNode& node)
{
    quint8 b;

    if (!readInt8(b))
        return false;

    int size = -1;
    if (!readListSize(b, size))
        return false;
    if (size < 0)
        return false;

    if (!readInt8(b))
        return false;

    if (b == 2)
        return false;

    QByteArray tag;
    if (!readString(b, tag))
        return false;

    int attribCount = (size - 2 + size % 2) / 2;

    AttributeList attribs;
    if (!readAttributes(attribs,attribCount))
        return false;

    node.setTag(tag);
    node.setAttributes(attribs);

    if ((size % 2) == 1)
        return true;

    if (!readInt8(b))
        return false;

    if (isListTag(b))
    {
        return readList(b,node);
    }

    QByteArray data;
    if (!readString(b,data))
        return false;

    node.setData(data);
    return true;
}
Пример #5
0
void BinTreeNodeReader::streamStart()
{
	this->getTopLevelStream();

	int tag = this->in->read();
	int size = readListSize(tag);
	tag = this->in->read();
	if (tag != 1)
		throw WAException("expecting STREAM_START in streamStart", WAException::CORRUPT_STREAM_EX, 0);

	int attribCount = (size - 2 + size % 2) / 2;
	std::map<string, string>* attributes = readAttributes(attribCount);
	delete attributes;
}
Пример #6
0
bool BinTreeNodeReader::readList(qint32 token,ProtocolTreeNode& node)
{
    int size = 0;
    if (!readListSize(token, size)) {
        qDebug() << "failed to read listSize";
        return false;
    }
    for (int i=0; i<size; i++)
    {
        ProtocolTreeNode child;
        //TODO: check results
        nextTreeInternal(child);
        node.addChild(child);
    }
    return true;
}
Пример #7
0
ProtocolTreeNode* BinTreeNodeReader::nextTreeInternal()
{
	int b = this->in->read();
	int size = readListSize(b);
	b = this->in->read();
	if (b == 2)
		return NULL;

	std::string* tag = this->readStringAsString(b);

	if ((size == 0) || (tag == NULL))
		throw WAException("nextTree sees 0 list or null tag", WAException::CORRUPT_STREAM_EX, -1);
	int attribCount = (size - 2 + size % 2) / 2;
	std::map<string, string>* attribs = readAttributes(attribCount);
	if (size % 2 == 1) {
		ProtocolTreeNode* ret = new ProtocolTreeNode(*tag); ret->attributes = attribs;
		delete tag;
		return ret;
	}
	b = this->in->read();
	if (isListTag(b)) {
		ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, NULL, readList(b)); ret->attributes = attribs;
		delete tag;
		return ret;
	}

	ReadData* obj = this->readString(b);
	std::vector<unsigned char>* data;
	if (obj->type == STRING) {
		std::string* s = (std::string*) obj->data;
		data = new std::vector<unsigned char>(s->begin(), s->end());
		delete s;
	}
	else data = (std::vector<unsigned char>*) obj->data;

	ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, data); ret->attributes = attribs;
	delete obj;
	delete tag;
	return ret;
}