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

minor changes

parent 8c7932b6
......@@ -61,4 +61,5 @@ HEADERS += \
DISTFILES += \
README.md \
design.md \
persons.proto
persons.proto \
samples.txt
......@@ -36,6 +36,8 @@ or [Qt data model](https://doc.qt.io/qt-5/model-view-programming.html).
* **W5. Good support of Qt data**:
1. almost all features of simple data (QJson..., QDataStream, *QSettings (TBD)*)
2. most features of complex data (QCbor..., QXml..., QMetaObject, QModel...)
* **W6. No restriction on output data size**
(some restrictions may apply with specific implementations that may, e.g. store context for each data structure levels)
### Read (deserialization)
......@@ -49,11 +51,14 @@ or [Qt data model](https://doc.qt.io/qt-5/model-view-programming.html).
* **R3. Allow reporting all errors** and mismatches between what was expected and what is read (unless the data format was implicit as below)
* **R4. Allow implicit formats like QDataStream** when the reader knows exactly what to read
* **R5. Allow optional metadata for complex formats** (CBOR tags, XML tags and attributes, QModel* columnNames, etc.)
* **R6. No restriction on input data size or shape**
(some restrictions may apply with specific implementations that may, e.g. cache out-of-order data)
### A notable non-requirement
**QBind does not _automatically_ support (de)serialization of graphs unlike boost::serialization**. User must choose an appropriate
encoding using some kind of "reference" values. We argue this makes the model translatable to much more data formats like Json since
**QBind does not _automatically_ support (de)serialization of graphs unlike boost::serialization**. Pointers will be followed and in
case of a graph with a loop, the operation will result in a stack overflow. Hence, the user has to choose an appropriate encoding for his
graph data using some kind of "reference" values. We argue this makes the model translatable to much more data formats like Json since
it does not mandate native support for references. Moreover, QBind supports metadata as an optional way to encode such special values
for data formats supporting it like [CBOR value sharing tags](http://cbor.schmorp.de/value-sharing) and XML.
......@@ -89,7 +94,7 @@ QBind allows binding C++ `data` to a choice of:
- *uuid (TBD)*
* Generically supported T values for which a specialized QBind<T>::bind() is defined
We argue that QBind allows lossless conversions between all supported formats, and that the addition of optional metadata (R6)
We argue that QBind allows lossless conversions between all supported formats, and that the addition of optional metadata (R5)
can address most peculiarities of the supported formats. However, it may not always conveniently address formats that do not have standard
ways of representing data structures such as XML (e.g. binding the Person type with enough metadata to conform the result to
[xCard schema](https://tools.ietf.org/html/rfc6351) would be cumbersome).
......@@ -123,12 +128,12 @@ struct Person
Cursor bind(Val<Cursor>&& value) { // works with value->mode()==Read as well as Write
return value
.record("Person")
.sequence("names")
.sequence("names") // to illustrate a basic mapping between concrete struct Person and a more general data schema
.bind(firstName)
.bind( lastName)
.out()
.bind("height" ,height )
.bind("age" ,age ,-1) // reads null() as -1
.bind("height" ,height ) // keyed items such as "names" and "height" may appear in any order in a record()
.bind("age" ,age ,-1) // reads null() or missing values as the default value: -1
.bind("phones" ,phones ) // recursive calls to QBind will take care of that part
.bind("comments",comments)
.bind("children",children)
......@@ -157,7 +162,7 @@ s.startMap();
s.endArray();
s.append("comments"); s.append(person.comments.toUtf8().constData());
s.append("children"); s.startArray();
if (!person.children.isEmpty()) {} // TODO
//...
s.endArray();
s.endMap();
```
......@@ -208,15 +213,9 @@ if (reader.next() &&
reader.readString().status==QCborStreamReader::EndOfString &&
reader.isArray() &&
reader.enterContainer() &&
reader.hasNext() &&
reader.isString())
p.phones.append(reader.readString().data);
if (reader.readString().status==QCborStreamReader::EndOfString &&
reader.hasNext() &&
reader.isString())
p.phones.append(reader.readString().data);
if (reader.readString().status==QCborStreamReader::EndOfString &&
!reader.hasNext() &&
reader.hasNext() /*&& ...*/)
//...
if (/*... &&*/
reader.leaveContainer() &&
reader.hasNext() &&
reader.isString() &&
......@@ -250,7 +249,7 @@ protected:
};
```
With the addition of a << shortcut method, MyTextWriter can mimic QDebug and replace it in existing code:
With the addition of a shortcut `operator<<`, MyTextWriter can mimic QDebug and replace it in existing code:
```cpp
// 1.33333 3.14159 ascii characters are common in QDebug false QColor(ARGB 1, 0.176471, 0, 0.729412)
QDebug (&s ) << 1.333333333333f << PI << ascii << false << color ;
......
......@@ -8,7 +8,7 @@ Cbor |85fa3faaaaabfb400921fb54442d1878256173636969206368617261637465727
QCborStream |85fa3faaaaabfb400921fb54442d187825617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567f4bf635247429f182d0018baff646261736518ffff
Data |3ff5555560000000400921fb54442d1800000026617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567000001ffff2d2d0000baba0000
QDataStream |3ff5555560000000400921fb54442d1800000026617363696920636861726163746572732061726520636f6d6d6f6e20696e20514465627567000001ffff2d2d0000baba0000
QByteArray |abaaaa3f182d4454fb210940617363696920636861726163746572732061726520636f6d6d6f6e20696e205144656275670001000000ffff2d2d0000baba00003a77
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}]
......@@ -43,14 +43,14 @@ Writable>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc000000000
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 |(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>Json |{"names":["John","Doe"],"height":1.7500000000000002,"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:58 Ignored character 0:147 Ignored character 0:148 Expected record 0:148]
P>JsonValue |{
"age": -1,
"children": [
],
"comments": "",
"height": 1.75,
"height": 1.7500000000000004,
"names": [
"John",
"Doe"
......@@ -71,7 +71,7 @@ JsonValue>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[ (Phone)[
Json>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fa3fe0000063616765206670686f6e65739fbf647479706502666e756d6265726130ffbf647479706503666e756d6265726130ffff68636f6d6d656e747360686368696c6472656e9fffff
Json>JsonValue|{
}
[ 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]
[ Ignored character 0:147 Ignored character 0:148 Expected null 0:148 Expected record 0:148 Expected text 0:148 Expected boolean 0:148 Expected decimal 0:148 Expected decimal 0:148 Expected decimal 0:148 Expected null 0:148 Expected text 0:148 Expected boolean 0:148 Expected decimal 0:148 Expected decimal 0:148 Expected decimal 0:148 Expected null 0:148]
group |Person<>Cbor
Cbor>P |(Person)[ names:[ John Doe] height:1.75 age:-1 phones:[] comments: children:[]][]
P>Cbor |bf656e616d65739f644a6f686e63446f65ff66686569676874fb3ffc00000000000063616765206670686f6e65738068636f6d6d656e747360686368696c6472656e80ff
......
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