void readValueEmbeddedMap(ContentBuffer & reader, RecordParseListener & listener, OType mapType) { int64_t size = readVarint(reader); listener.startMap(size, mapType); int32_t lastCursor = 0; while (size-- > 0) { //Skipping because is everytime string reader.prepare(1); int key_size = readVarint(reader); reader.prepare(key_size); char * key_name = (char *) reader.content + reader.cursor; listener.mapKey(key_name, key_size); long position = readFlat32Integer(reader); reader.prepare(1); if (position == 0) { listener.nullValue(); } else { OType type = (OType) reader.content[reader.cursor]; int temp = reader.prepared; reader.force_cursor(position); readSimpleValue(reader, type, listener); lastCursor = reader.prepared; reader.force_cursor(temp); } } listener.endMap(mapType); if (lastCursor > reader.prepared) reader.force_cursor(lastCursor); }
bool ParseContext::handleStartElement(QXmlStreamReader &r) { const QStringRef name = r.name(); const Element e = element(name); if (e == VariableElement) { m_currentVariableName = r.readElementText(); return false; } if (!ParseContext::isValueElement(e)) return false; const QXmlStreamAttributes attributes = r.attributes(); const QString key = attributes.hasAttribute(keyAttribute) ? attributes.value(keyAttribute).toString() : QString(); switch (e) { case SimpleValueElement: // This reads away the end element, so, handle end element right here. m_valueStack.push_back(ParseValueStackEntry(readSimpleValue(r, attributes), key)); return handleEndElement(name); case ListValueElement: m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key)); break; case MapValueElement: m_valueStack.push_back(ParseValueStackEntry(QVariant::Map, key)); break; default: break; } return false; }
void readValueEmbeddedCollection(ContentBuffer & reader, RecordParseListener & listener, OType collType) { int size = readVarint(reader); listener.startCollection(size, collType); reader.prepare(1); OType type = (OType) reader.content[reader.cursor]; if (ANY == type) { while (size-- > 0) { reader.prepare(1); OType entryType = (OType) reader.content[reader.cursor]; if (ANY == entryType) listener.nullValue(); else readSimpleValue(reader, entryType, listener); } } listener.endCollection(collType); //For now else is impossible }
void readDocument(ContentBuffer &reader, RecordParseListener & listener) { int64_t class_size = readVarint(reader); if (class_size != 0) { reader.prepare(class_size); char * class_name = (char *) reader.content + reader.cursor; listener.startDocument(class_name, class_size); } else listener.startDocument("", 0); int64_t size = 0; int32_t lastCursor = 0; while ((size = readVarint(reader)) != 0) { if (size > 0) { reader.prepare(size); char * field_name = (char *) reader.content + reader.cursor; int32_t position = readFlat32Integer(reader); reader.prepare(1); if (position == 0) { listener.startField(field_name, size, ANY); listener.nullValue(); } else { OType type = (OType) reader.content[reader.cursor]; listener.startField(field_name, size, type); int temp = reader.prepared; reader.force_cursor(position); readSimpleValue(reader, type, listener); lastCursor = reader.prepared; reader.force_cursor(temp); } listener.endField(field_name, size); } else { throw new parse_exception("property id not supported by network serialization"); } } listener.endDocument(); if (lastCursor > reader.prepared) reader.force_cursor(lastCursor); }
bool ParseContext::handleStartElement(QXmlStreamReader &r) { const QStringRef name = r.name(); const Element e = element(name); if (e == VariableElement) { m_currentVariableName = r.readElementText(); return false; } if (!ParseContext::isValueElement(e)) return false; const QXmlStreamAttributes attributes = r.attributes(); const QString key = attributes.hasAttribute(keyAttribute) ? attributes.value(keyAttribute).toString() : QString(); switch (e) { case SimpleValueElement: { // This reads away the end element, so, handle end element right here. const QVariant v = readSimpleValue(r, attributes); if (!v.isValid()) { qWarning() << ParseContext::formatWarning(r, QString::fromLatin1("Failed to read element \"%1\".").arg(name.toString())); return false; } m_valueStack.push_back(ParseValueStackEntry(v, key)); return handleEndElement(name); } case ListValueElement: m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key)); break; case MapValueElement: m_valueStack.push_back(ParseValueStackEntry(QVariant::Map, key)); break; default: break; } return false; }