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

Few fixes for QCborValue to finally get back accurate benchmark

parent 1cb35bb0
......@@ -803,7 +803,9 @@ template<typename T, class TResult> //=Cursor
struct QBind<QBindDefault<T>, TResult> {
static TResult bind(Val<TResult>&& v, QBindDefault<T>&& t) {
if (v->mode()==Read) {
v->setChoice(true);
auto r=v.null();
v->setChoice(false);
if (r) {
t.value = t.defaultValue;
return r;
......
......@@ -194,11 +194,12 @@ protected:
bool _record (quint32* =nullptr) { levels.push(Step("" )); return true; }
bool _null ( ) { set(QCborValue( )); return true; }
bool _bind ( const char* s) { set(QCborValue(s)); return true; }
bool _bind ( bool& b) { set(QCborValue(b)); return true; }
bool _bind ( float& d) { set(QCborValue(double(d))); return true; }
bool _bind ( double& d) { set(QCborValue(d)); return true; }
bool _bind ( quint64& n) { double d(n); return _bind(d); }
bool _bind ( qint64& n) { double d(n); return _bind(d); }
bool _bind ( bool&& b) { set(QCborValue(b)); return true; }
bool _bind ( float&& d) { set(QCborValue(double(d))); return true; }
bool _bind ( double&& d) { set(QCborValue(d)); return true; }
bool _bind ( quint64&& n) { if (std::numeric_limits<qint64>::max()<n) { _reportError(qBindExpectedSmallerNumber); return false; }
set(QCborValue(qint64(n))); return true; }
bool _bind ( qint64&& n) { set(QCborValue(n)); return true; }
bool _bind ( QByteArray&& s) { set(QCborValue(s)); return true; }
bool _item(QName n) { levels.last().key=n ; return true; }
......@@ -254,8 +255,8 @@ protected:
bool _bind ( QUtf8String& u) { QString s; if (_bind(s) ) { u = s.toUtf8() ; return true; } return false; }
bool _bind ( QString& v) { if (current().isString ()) { v = current().toString (); return true; } _reportError(qBindExpectedText ); return false; }
bool _bind ( bool& v) { if (current().isBool ()) { v = current().toBool (); return true; } _reportError(qBindExpectedBoolean ); return false; }
bool _bind ( qint64& t) { double d; if (_bind(d) ) { t = qint64(d) ; return true; } return false; }
bool _bind ( quint64& t) { double d; if (_bind(d) ) { t = quint64(d) ; return true; } return false; }
bool _bind ( qint64& t) { if (current().isInteger ()) { t = current().toInteger (); return true; } _reportError(qBindExpectedInteger ); return false; }
bool _bind ( quint64& t) { qint64 i; if (_bind(i) ) { t = quint64(i) ; return true; } return false; }
bool _bind ( float& v) { double d; if (_bind(d) ) { v = float(d) ; return true; } return false; }
bool _bind ( double& v) { if (current().isDouble ()) { v = current().toDouble (); return true; } _reportError(qBindExpectedDecimal ); return false; }
bool _bind ( QByteArray& v) { QString s; if (current().isByteArray()) { v = current().toByteArray(); return true; } _reportError(qBindExpectedBytes ); return false; }
......@@ -267,7 +268,8 @@ protected:
bool _isOk() { return cbor; }
void _setChoice(bool v) { isChoice=v; }
void _reportError(const char* e) { if (!isChoice) errors.append(Error{ e, currentPath() }); }
void _reportError(const char* e) { if (!isChoice)
errors.append(Error{ e, currentPath() }); }
private:
const QCborValue& current(int outer=0) const { Q_ASSERT(0<=outer); return steps.size()-outer <= 0 ? *cbor : steps[steps.size()-outer-1].item; }
......
......@@ -639,7 +639,6 @@ int main(int argc, char *argv[])
Person p;
QBuffer roundtrip; roundtrip.open(QIODevice::ReadWrite);
QJsonValue jv;
QCborValue cv;
QVector<QJsonReader ::Error> readerErrors;
QVector<QJsonVisitor::Error> visitorErrors;
//---------------------------------------------------------------------
......@@ -700,7 +699,6 @@ int main(int argc, char *argv[])
// { "names": [ "John", "Doe"], "age":null,"height": 1.75, "phones": [ { "type": 2,"number": "+44 1234567"}, { "type": 3,"number": "+44 2345678"}], "":"superfluous item"}
Person p;
QBuffer roundtrip; roundtrip.open(QIODevice::ReadWrite);
QJsonValue jv;
QCborValue cv;
QVector<QCborReader ::Error> readerErrors;
QVector<QCborVisitor::Error> visitorErrors;
......
......@@ -8,7 +8,7 @@ Cbor |85fa3faaaaabfb400921fb54442d1878256173636969206368617261637465727
QCborStream |85fa3faaaaabfb400921fb54442d187825617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567f4bf635247429f182d0018baff646261736518ffff
Data |3ff5555560000000400921fb54442d1800000026617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567000001ffff2d2d0000baba0000
QDataStream |3ff5555560000000400921fb54442d1800000026617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567000001ffff2d2d0000baba0000
QByteArray |abaaaa3f182d4454fb210940617363696920636861726163746572732061726520636f6d6d6f6e20696e205144656275670001000000ffff2d2d0000baba0000e000
QByteArray |abaaaa3f182d4454fb210940617363696920636861726163746572732061726520636f6d6d6f6e20696e205144656275670001000000ffff2d2d0000baba00000000
Writables |
Writables>Cbor|85fa3faaaaabfb400921fb54442d187825617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567f4bf635247429f182d0018baff646261736518ffff
Writables>Json|[1.33333337,3.1415926535897931,"ascii characters are common in QDebug",false,{"RGB":[45,0,186],"base":255}]
......@@ -44,7 +44,7 @@ Writable>Json |{"names":["John","Doe"],"height":1.75,"age":18,"phones":[{"type":
group |Person<>Json
Json>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][ Ignored character 0:1 Ignored character 0:15 Ignored character 0:23 Ignored character 0:40 Ignored character 0:42 Ignored character 0:58 Ignored character 0:172]
P>Json |{"names":["John","Doe"],"height":1.7500000000000002,"age":-1,"phones":[{"type":2,"number":"+44 1234567"},{"type":3,"number":"+44 2345678"}],"comments":"","children":[]}
Json>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][ Expected null 0:58 Ignored character 0:167 Ignored character 0:168 Expected record 0:168]
Json>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][ Ignored character 0:167 Ignored character 0:168 Expected record 0:168]
P>JsonValue |{
"age": -1,
"children": [
......@@ -67,7 +67,7 @@ P>JsonValue |{
]
}
JsonValue>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][ ]
JsonValue>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][]
Json>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fa3fe0000063616765206670686f6e65739fbf647479706502666e756d6265726b2b34342031323334353637ffbf647479706503666e756d6265726b2b34342032333435363738ffff68636f6d6d656e747360686368696c6472656e9fffff
Json>JsonValue|{
}
......@@ -75,10 +75,10 @@ Json>JsonValue|{
group |Person<>Cbor
Cbor>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][]
P>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765206670686f6e657382bf647479706502666e756d6265726b2b34342031323334353637ffbf647479706503666e756d6265726b2b34342032333435363738ff68636f6d6d656e747360686368696c6472656e80ff
Cbor>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][ Expected null 38]
Cbor>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][]
QCborStream>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]]true
P>CborValue |a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765622d316670686f6e657382a264747970656132666e756d6265726b2b34342031323334353637a264747970656133666e756d6265726b2b3434203233343536373868636f6d6d656e747360686368696c6472656e80
CborValue>P |(Person)[ names:[ John Doe] height:1.75 age:0 phones:[] comments: children:[]][ ]
P>CborValue |a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765206670686f6e657382a2647479706502666e756d6265726b2b34342031323334353637a2647479706503666e756d6265726b2b3434203233343536373868636f6d6d656e747360686368696c6472656e80
CborValue>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments: children:[]][]
Cbor>CborValue|{"names": ["John", "Doe"], "height": 1.75, "age": -1, "phones": [{"type": 2, "number": "+44 1234567"}, {"type": 3, "number": "+44 2345678"}], "comments": "", "children": []}[]
Cbor<CborValue|a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765206670686f6e657382a2647479706502666e756d6265726b2b34342031323334353637a2647479706503666e756d6265726b2b3434203233343536373868636f6d6d656e747360686368696c6472656e80
Cbor>Json |{"names":["John","Doe"],"height":1.75,"age":}[]
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