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

Use QMetaEnum as meta in TextWriter but not value in Json or Cbor

parent 7254a8b6
......@@ -546,7 +546,7 @@ struct IWriter : public IBind
// QDataStream format is the only Qt data format that is read-write and easily extensible by users
// It is binary and includes src.typeName() for QMetaType::User types
// QByteArray will be encoded a QVariant to avoid ambiguities when decoding bytes
// QByteArray will be encoded into a QVariant to avoid ambiguities when decoding bytes
QByteArray binaryVariant; QDataStream s(&binaryVariant, QIODevice::WriteOnly);
s << src;
......@@ -760,12 +760,23 @@ TResult qbind(Val<TResult>&& v, T* t) {
if (rw==Read) {
QVariant pv;
r = r.bind(p.name(),pv);
if ((!r && p.isResettable() && !p.resetOnGadget(t)) || !p.writeOnGadget(t, pv)) {
if ((!r && p .isResettable () && !p.resetOnGadget(t)) ||
( r && pv.canConvert<int>() && !p.writeOnGadget(t, pv.toInt()))) {
v->reportError(qBindIgnoredItem);
}
}
else if (rw==Write) {
r = r.bind(p.name(), p.readOnGadget(t));
QVariant pv = p.readOnGadget(t);
if (/*pv.isValid() &&*/ !pv.isNull()) {
auto i = r.item(p.name());
if (p.isFlagType() && pv.canConvert<int>()) {
i = i.meta({{qmName, p.enumerator().valueToKeys(pv.toInt())}});
}
else if (p.isEnumType() && pv.canConvert<int>()) {
i = i.meta({{qmName, p.enumerator().valueToKey(pv.toInt())}});
}
r = i.bind(pv);
}
}
else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); }
}
......
......@@ -190,6 +190,8 @@ protected:
bool _item(QName n) { ba->append(" "); ba->append(n); ba->append(":"); return true; }
bool _item( ) { ba->append(" ") ; return true; }
bool _out ( ) { ba->append("]") ; return true; }
void _meta(QMetaData& m) { bool isFirst=true; for (auto kv: m) { ba->append(isFirst?"(":" "); isFirst=false; if (kv.first!=qmName) { ba->append(kv.first); ba->append(":"); } ba->append(kv.second.toUtf8()); } if (!isFirst) { ba->append(")"); } }
private:
QByteArray* ba;
};
......@@ -243,7 +245,7 @@ int main(int argc, char *argv[])
// Generated files
FILE* results; fopen_s(&results, "results.csv", "w");
FILE* samples; fopen_s(&samples, "samples.txt", "w");
FILE* samples; fopen_s(&samples, "../QBind/samples.txt", "w");
if (!(results && samples))
return -1;
......@@ -633,8 +635,8 @@ int main(int argc, char *argv[])
GROUP("Person<>Json")//====================================================
{
QBuffer json; json.open(QIODevice::ReadOnly);
json.buffer() = "_{ \"names\": [ _\"John\" _, \"Doe\"] , \"age\"_:_null, \"height\":_1.75, \"phones\": [ {\"type\":\"Home\",\"number\":\"+44 1234567\"} , {\"type\":\"Office\",\"number\":\"+44 2345678\"} ], \"\":\"superfluous item\" _} ";
// 1 15 23 4042 58 184
json.buffer() = "_{ \"names\": [ _\"John\" _, \"Doe\"] , \"age\"_:_null, \"height\":_1.75, \"phones\": [ {\"type\":2,\"number\":\"+44 1234567\"} , {\"type\":3,\"number\":\"+44 2345678\"} ], \"\":\"superfluous item\" _} ";
// 1 15 23 4042 58 172
Person p;
QBuffer roundtrip; roundtrip.open(QIODevice::ReadWrite);
QJsonValue jv;
......@@ -695,8 +697,8 @@ int main(int argc, char *argv[])
{
QBuffer cbor; cbor.open(QIODevice::ReadOnly);
cbor.buffer() = QByteArray::fromHex(
"A5656E616D657382644A6F686E63446F6563616765F666686569676874F93F006670686F6E657382A264747970650166E756D6265726B2B34342031323334353637A264747970650266E756D6265726B2B3434203233343536373860707375706572666C756F7573206974656D");
// { "names": [ "John" , "Doe"] , "age":null, "height":1.75, "phones": [ {"type":1,"number":"+44 1234567"} , {"type":2,"number":"+44 2345678"} ], "":"superfluous item" }
"A5656E616D657382644A6F686E63446F6563616765F666686569676874F93F006670686F6E657382A264747970650266E756D6265726B2B34342031323334353637A264747970650366E756D6265726B2B3434203233343536373860707375706572666C756F7573206974656D");
// { "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;
......
group |builtin>
QDebug |1.33333 3.14159 ascii characters are common in QDebug false QColor(ARGB 1, 0.176471, 0, 0.729412)
Text |[ 1.33333337 3.1415926535897931 ascii characters are common in QDebug false [ RGB:[ 45 0 186] base:255]
Text |[ 1.33333 3.14159 ascii characters are common in QDebug false [ RGB:[ 45 0 186] base:255]
Json |[1.33333337,3.1415926535897931,"ascii characters are common in QDebug",false,{"RGB":[45,0,186],"base":255}]
Xml |<sequence><decimal>1.33333337</decimal><decimal>3.1415926535897931</decimal><string>ascii characters are common in QDebug</string><boolean>false</boolean><record><RGB><integer>45</integer><integer>0</integer><integer>186</integer></RGB><base>255</base></record>
Variant |
Cbor |85fa3faaaaabfb400921fb54442d187825617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567f4bf635247429f182d0018baff646261736518ffff
QCborStream |85fa3faaaaabfb400921fb54442d187825617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567f4bf635247429f182d0018baff646261736518ffff
Data |3ff5555560000000400921fb54442d1800000026617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567000001ffff2d2d0000baba0000
QDataStream |3ff5555560000000400921fb54442d1800000026617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567000001ffff2d2d0000baba0000
QByteArray |abaaaa3f182d4454fb210940617363696920636861726163746572732061726520636f6d6d6f6e20696e205144656275670001000000ffff2d2d0000baba00003a77
Writables |
Writables>Cbor|85fa3faaaaabfb400921fb54442d187825617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567f4bf635247429f182d0018baff646261736518ffff
Writables>Json|[1.33333337,3.1415926535897931,"ascii characters are common in QDebug",false,{"RGB":[45,0,186],"base":255}]
group |doubles>
QDebug |0.333333 0.666667 0.333333 1 0.666667 0.333333 0.666667 1 0.333333 0.666667 0.333333 1 0 0 0 1
Text |[ 0.33333333333333331 0.66666666666666663 0.33333333333333331 1 0.66666666666666663 0.33333333333333331 0.66666666666666663 1 0.33333333333333331 0.66666666666666663 0.33333333333333331 1 0 0 0 1]
Text |[ 0.333333 0.666667 0.333333 1 0.666667 0.333333 0.666667 1 0.333333 0.666667 0.333333 1 0 0 0 1]
Json |[0.33333333333333331,0.66666666666666663,0.33333333333333331,1,0.66666666666666663,0.33333333333333331,0.66666666666666663,1,0.33333333333333331,0.66666666666666663,0.33333333333333331,1,0,0,0,1]
Xml |<sequence><decimal>0.33333333333333331</decimal><decimal>0.66666666666666663</decimal><decimal>0.33333333333333331</decimal><decimal>1</decimal><decimal>0.66666666666666663</decimal><decimal>0.33333333333333331</decimal><decimal>0.66666666666666663</decimal><decimal>1</decimal><decimal>0.33333333333333331</decimal><decimal>0.66666666666666663</decimal><decimal>0.33333333333333331</decimal><decimal>1</decimal><decimal>0</decimal><decimal>0</decimal><decimal>0</decimal><decimal>1</decimal></sequence>
Variant |
Cbor |90fb3fd5555555555555fb3fe5555555555555fb3fd5555555555555fb3ff0000000000000fb3fe5555555555555fb3fd5555555555555fb3fe5555555555555fb3ff0000000000000fb3fd5555555555555fb3fe5555555555555fb3fd5555555555555fb3ff0000000000000fb0000000000000000fb0000000000000000fb0000000000000000fb3ff0000000000000
QCborStream |90fb3fd5555555555555fb3fe5555555555555fb3fd5555555555555fb3ff0000000000000fb3fe5555555555555fb3fd5555555555555fb3fe5555555555555fb3ff0000000000000fb3fd5555555555555fb3fe5555555555555fb3fd5555555555555fb3ff0000000000000fb0000000000000000fb0000000000000000fb0000000000000000fb3ff0000000000000
......@@ -24,22 +27,24 @@ Writable |
Writable>Cbor |90fb3fd5555555555555fb3fe5555555555555fb3fd5555555555555fb3ff0000000000000fb3fe5555555555555fb3fd5555555555555fb3fe5555555555555fb3ff0000000000000fb3fd5555555555555fb3fe5555555555555fb3fd5555555555555fb3ff0000000000000fb0000000000000000fb0000000000000000fb0000000000000000fb3ff0000000000000
Writable>Json |[0.33333333333333331,0.66666666666666663,0.33333333333333331,1,0.66666666666666663,0.33333333333333331,0.66666666666666663,1,0.33333333333333331,0.66666666666666663,0.33333333333333331,1,0,0,0,1]
group |Person>
QDebug |"John" "Doe" 1.75 18 QVector("+44 1234567", "+44 2345678") "unicode is likely U+01 \u0001 + U+1F \u001F + U+A4 U+B0 U+D8 U+FF "
Text |[ names:[ John Doe] height:1.75 age:18 phones:[ +44 1234567 +44 2345678] comments:unicode is likely U+01  + U+1F  + U+A4 U+B0 U+D8 U+FF children:[]]
Json |{"names":["John","Doe"],"height":1.75,"age":18,"phones":["+44 1234567","+44 2345678"],"comments":"unicode is likely U+01 \u0001 + U+1F \u001F + U+A4 U+B0 U+D8 U+FF ","children":[]}
QDebug |"John" "Doe" 1.75 18 QVector(Phone(Phone::Home, "+44 1234567"), Phone(Phone::Office, "+44 2345678")) "unicode is likely U+01 \u0001 + U+1F \u001F + U+A4 U+B0 U+D8 U+FF "
Text |(Person)[ names:[ John Doe] height:1.75 age:18 phones:[ (Phone)[ type:(Home)2 number:+44 1234567] (Phone)[ type:(Office)3 number:+44 2345678]] comments:unicode is likely U+01  + U+1F  + U+A4 U+B0 U+D8 U+FF children:[]]
Json |{"names":["John","Doe"],"height":1.75,"age":18,"phones":[{"type":2,"number":"+44 1234567"},{"type":3,"number":"+44 2345678"}],"comments":"unicode is likely U+01 \u0001 + U+1F \u001F + U+A4 U+B0 U+D8 U+FF ","children":[]}
Xml |<Person><names><string>John</string><string>Doe</string></names><height>1.75</height><age>18</age><phones><Phone><Home>2</Home><number>+44 1234567</number></Phone><Phone><Office>3</Office><number>+44 2345678</number></Phone></phones><comments>unicode is likely U+01 + U+1F + U+A4 U+B0 U+D8 U+FF </comments><children/></Person>
Variant |
Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765126670686f6e6573826b2b343420313233343536376b2b3434203233343536373868636f6d6d656e74737843756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf686368696c6472656e80ff
QCborStream |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765126670686f6e6573826b2b343420313233343536376b2b3434203233343536373868636f6d6d656e74737843756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf686368696c6472656e9fffff
Data |00000008004a006f0068006e000000060044006f00653ffc000000000000000000120000000200000016002b003400340020003100320033003400350036003700000016002b00340034002000320033003400350036003700380000007e0075006e00690063006f006400650020006900730020006c0069006b0065006c007900200055002b00300031002000010020002b00200055002b003100460020001f0020002b00200055002b00410034002000a400200055002b00420030002000b000200055002b00440038002000d800200055002b00460046002000ff00000000
QDataStream |00000008004a006f0068006e000000060044006f00653ffc000000000000000000120000000200000016002b003400340020003100320033003400350036003700000016002b00340034002000320033003400350036003700380000007e0075006e00690063006f006400650020006900730020006c0069006b0065006c007900200055002b00300031002000010020002b00200055002b003100460020001f0020002b00200055002b00410034002000a400200055002b00420030002000b000200055002b00440038002000d800200055002b00460046002000ff00000000
QByteArray |4a6f686e446f65000000000000fc3f7a0000002b343420313233343536372b34342032333435363738756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf
Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765126670686f6e657382bf647479706502666e756d6265726b2b34342031323334353637ffbf647479706503666e756d6265726b2b34342032333435363738ff68636f6d6d656e74737843756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf686368696c6472656e80ff
QCborStream |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765126670686f6e657382bf647479706502666e756d6265726b2b34342031323334353637ffbf647479706503666e756d6265726b2b34342032333435363738ff68636f6d6d656e74737843756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf686368696c6472656e9fffff
Data |00000008004a006f0068006e000000060044006f00653ffc00000000000000000012000000020200000016002b00340034002000310032003300340035003600370300000016002b00340034002000320033003400350036003700380000007e0075006e00690063006f006400650020006900730020006c0069006b0065006c007900200055002b00300031002000010020002b00200055002b003100460020001f0020002b00200055002b00410034002000a400200055002b00420030002000b000200055002b00440038002000d800200055002b00460046002000ff00000000
QDataStream |00000008004a006f0068006e000000060044006f00653ffc00000000000000000012000000020200000016002b00340034002000310032003300340035003600370300000016002b00340034002000320033003400350036003700380000007e0075006e00690063006f006400650020006900730020006c0069006b0065006c007900200055002b00300031002000010020002b00200055002b003100460020001f0020002b00200055002b00410034002000a400200055002b00420030002000b000200055002b00440038002000d800200055002b00460046002000ff00000000
QByteArray |4a6f686e446f65000000000000fc3f12000000020000002b343420313233343536372b34342032333435363738756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf00000000
Writable |
Writable>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765126670686f6e6573826b2b343420313233343536376b2b3434203233343536373868636f6d6d656e74737843756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf686368696c6472656e80ff
Writable>Json |{"names":["John","Doe"],"height":1.75,"age":18,"phones":["+44 1234567","+44 2345678"],"comments":"unicode is likely U+01 \u0001 + U+1F \u001F + U+A4 U+B0 U+D8 U+FF ","children":[]}
Writable>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765126670686f6e657382bf647479706502666e756d6265726b2b34342031323334353637ffbf647479706503666e756d6265726b2b34342032333435363738ff68636f6d6d656e74737843756e69636f6465206973206c696b656c7920552b30312001202b20552b3146201f202b20552b413420c2a420552b423020c2b020552b443820c39820552b464620c3bf686368696c6472656e80ff
Writable>Json |{"names":["John","Doe"],"height":1.75,"age":18,"phones":[{"type":2,"number":"+44 1234567"},{"type":3,"number":"+44 2345678"}],"comments":"unicode is likely U+01 \u0001 + U+1F \u001F + U+A4 U+B0 U+D8 U+FF ","children":[]}
group |Person<>Json
Json>P |[ names:[ John Doe] height:1.75 age:-1 phones:[ +44 1234567 +44 2345678] comments:[ 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:132]
P>Json |{"names":["John","Doe"],"height":1.75,"age":-1,"phones":["+44 1234567","+44 2345678"],"comments":"","children":[]}
Json>P |[ names:[ John Doe] height:1.75 age:-1 phones:[ +44 1234567 +44 2345678] comments:[ Expected null 0:44 Ignored character 0:113 Ignored character 0:114 Expected record 0:114]
Json>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:0] (Phone)[ type:(Office)3 number:0]] 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.75,"age":-1,"phones":[{"type":2,"number":"0"},{"type":3,"number":"0"}],"comments":"","children":[]}
Json>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:0] (Phone)[ type:(Office)3 number:0]] comments: children:[]][ Expected null 0:44 Ignored character 0:133 Ignored character 0:134 Expected record 0:134]
P>JsonValue |{
"age": -1,
"children": [
......@@ -51,23 +56,29 @@ P>JsonValue |{
"Doe"
],
"phones": [
"+44 1234567",
"+44 2345678"
{
"number": "0",
"type": 2
},
{
"number": "0",
"type": 3
}
]
}
JsonValue>P |[ names:[ John Doe] height:1.75 age:-1 phones:[ +44 1234567 +44 2345678] comments:[
Json>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fa3fe0000063616765206670686f6e65739f6b2b343420313233343536376b2b34342032333435363738ff68636f6d6d656e747360686368696c6472656e9fffff
JsonValue>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[ type:(Home)2 number:0] (Phone)[ type:(Office)3 number:0]] comments: children:[]][ ]
Json>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fa3fe0000063616765206670686f6e65739fbf647479706502666e756d6265726130ffbf647479706503666e756d6265726130ffff68636f6d6d656e747360686368696c6472656e9fffff
Json>JsonValue|{
}
[ Ignored character 0:113 Ignored character 0:114 Expected null 0:114 Expected record 0:114 Expected text 0:114 Expected boolean 0:114 Expected decimal 0:114 Expected decimal 0:114 Expected decimal 0:114 Expected null 0:114 Expected text 0:114 Expected boolean 0:114 Expected decimal 0:114 Expected decimal 0:114 Expected decimal 0:114 Expected null 0:114]
[ Ignored character 0:133 Ignored character 0:134 Expected null 0:134 Expected record 0:134 Expected text 0:134 Expected boolean 0:134 Expected decimal 0:134 Expected decimal 0:134 Expected decimal 0:134 Expected null 0:134 Expected text 0:134 Expected boolean 0:134 Expected decimal 0:134 Expected decimal 0:134 Expected decimal 0:134 Expected null 0:134]
group |Person<>Cbor
Cbor>P |[ names:[ John Doe] height:1.75 age:-1 phones:[ +44 1234567 +44 2345678] comments:[]
P>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765206670686f6e6573826b2b343420313233343536376b2b3434203233343536373868636f6d6d656e747360686368696c6472656e80ff
Cbor>P |[ names:[ John Doe] height:1.75 age:-1 phones:[ +44 1234567 +44 2345678] comments:[ Expected null 38]
QCborStream>P |[ names:[ John Doe] height:1.75 age:-1 phones:[ +44 1234567 +44 2345678] comments:false
P>CborValue |a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765622d316670686f6e6573826b2b343420313233343536376b2b3434203233343536373868636f6d6d656e747360686368696c6472656e80
CborValue>P |[ names:[ John Doe] height:1.75 age:0 phones:[] comments:[
Cbor>CborValue|{"names": ["John", "Doe"], "height": 1.75, "age": -1, "phones": ["+44 1234567", "+44 2345678"], "comments": "", "children": []}[]
Cbor<CborValue|a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765206670686f6e6573826b2b343420313233343536376b2b3434203233343536373868636f6d6d656e747360686368696c6472656e80
Cbor>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[]][]
P>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765206670686f6e65738068636f6d6d656e747360686368696c6472656e80ff
Cbor>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[]][ Expected null 38]
QCborStream>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[]]false
P>CborValue |a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765622d316670686f6e65738068636f6d6d656e747360686368696c6472656e80
CborValue>P |(Person)[ names:[ John Doe] height:1.75 age:0 phones:[] comments: children:[]][ ]
Cbor>CborValue|{"names": ["John", "Doe"], "height": 1.75, "age": -1, "phones": [], "comments": "", "children": []}[]
Cbor<CborValue|a6656e616d657382644a6f686e63446f6566686569676874fb3ffc00000000000063616765206670686f6e65738068636f6d6d656e747360686368696c6472656e80
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