Commit a268a829 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Reordered Read+Write from Json > Cbor

parent 1773d077
......@@ -299,14 +299,24 @@ int main()
QBuffer json;
json.open(QIODevice::ReadOnly);
json.buffer() = "_[ _\"John\" _, \"Doe\" , _1.75 , [ \"+44 1234567\" , \"+44 2345678\" ], \"superfluous item\" _] ";
QJsonValue v;
Person p;
QVector<QTextReadError> errors;
START {
json.seek(0); b.seek(0); b.buffer().clear();
QJsonReader(&json).bind(QCborWriter(&b).value());
}
STOP("Json>Cbor",QString::fromUtf8(b.buffer().toHex()))
START {
json.seek(0); v = QJsonValue();
errors = QJsonReader(&json).bind(v)->errors;
}
STOP("Json>JsonValue",QString::fromUtf8(QJsonDocument(v.toArray()).toJson())+QString(" errors:%1").arg(errors.size()));
START {
json.seek(0); p = {};
errors = QJsonReader(&json).bind(p)->errors;
}
STOP("Json>T",QString("[%1,%2,%3,[..%4..]] errors:%5").arg(p.firstName,p.lastName).arg(p.height).arg(p.phones.size()).arg(errors.size()))
QJsonValue v;
START {
QJsonBuilder(&v).bind(p);
}
......@@ -316,26 +326,16 @@ int main()
JsonVisitor(&v).bind(p);
}
STOP("JsonValue>T",QString("[%1,%2,%3,[..%4..]] errors:%5").arg(p.firstName,p.lastName).arg(p.height).arg(p.phones.size()).arg(errors.size()))
START {
json.seek(0); v = QJsonValue();
errors = QJsonReader(&json).bind(v)->errors;
}
STOP("Json>JsonValue",QString::fromUtf8(QJsonDocument(v.toArray()).toJson())+QString(" errors:%1").arg(errors.size()));
START {
b.seek(0); b.buffer().clear();
CborWriter(&b).bind(v);
}
STOP("JsonValue>Cbor",QString::fromUtf8(b.buffer().toHex()));
START {
b.seek(0); b.buffer().clear();
CborWriter(&b).bind(p);
}
STOP("T>Cbor",QString::fromUtf8(b.buffer().toHex()))
START {
json.seek(0); b.seek(0); b.buffer().clear();
QJsonReader(&json).bind(QCborWriter(&b).value());
b.seek(0); b.buffer().clear();
CborWriter(&b).bind(v);
}
STOP("Json>Cbor",QString::fromUtf8(b.buffer().toHex()))
STOP("JsonValue>Cbor",QString::fromUtf8(b.buffer().toHex()));
}
GROUP_STOP
return fclose(samples);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment