[Development] API review request: CBOR Stream reader and writer

Thiago Macieira thiago.macieira at intel.com
Wed Jan 24 19:49:32 CET 2018


On Wednesday, 17 January 2018 13:25:53 PST Thiago Macieira wrote:
> I'm also interested in what I could write as an example. Please send
> suggestions.

I've added a CBOR dump tool example, which can help you with understanding 
what you have:

$ convert/convert -o line-wrap=no /tmp/test3.cbor 
{ "Hello": false, "World": 1.2, "foo": [ 1.0, 2.0, 3.0 ] }
$ convert/convert /tmp/test3.cbor  
{
    "Hello": false,
    "World": 1.2,
    "foo": [
        1.0,
        2.0,
        3.0
    ]
}
$ cbordump/cbordump --compact /tmp/test3.cbor
55799({ "Hello": false, "World": 1.2, "foo": [ 1.0f, 2.0f, 3.0f ] })
$ cbordump/cbordump /tmp/test3.cbor           
55799({
    "Hello": false,
    "World": 1.2,
    "foo": [
        1.0f,
        2.0f,
        3.0f
    ]
})

You may be asking why the two tools print different output. What's that 55799 
and why do 1, 2 and 3 have "f" at the end? Well, the use the annotated mode:

$ cbordump/cbordump --annotated /tmp/test3.cbor 
d9 d9 f7                                           # Tag 55799 (Self-describe 
CBOR; see Section 2.4.5 [RFC7049])
  a3                                               # Map length 3
    65                                             # Text string length 5
      48 65 6c 6c 6f                               # "Hello"
    f4                                             # Simple Type false
    65                                             # Text string length 5
      57 6f 72 6c 64                               # "World"
    fb 3f f3 33 33 33 33 33 33                     # Double 1.2
    63                                             # Text string length 3
      66 6f 6f                                     # "foo"
    83                                             # Array length 3
      fa 3f 80 00 00                               # Float 1.
      fa 40 00 00 00                               # Float 2.
      fa 40 40 00 00                               # Float 3.

That 55799 allows this:
$ file /tmp/test3.cbor 
/tmp/test3.cbor: Concise Binary Object Representation (CBOR) container

The "f" indicate that it's a float, not double.

And just because I can:

$ qtplugininfo --full-json $QTOBJDIR/plugins/sqldrivers/libqsqlmysql.so | \
	 ./convert/convert -O cbor -o signature=no | \
	./cbordump/cbordump --annotated
a5                                                 # Map length 5
  63                                               # Text string length 3
    49 49 44                                       # "IID"
  78 2c                                            # Text string length 44
    6f 72 67 2e 71 74 2d 70 72 6f 6a 65 63 74 2e   # "org.qt-project."
    51 74 2e 51 53 71 6c 44 72 69 76 65 72 46 61   # "Qt.QSqlDriverFa"
    63 74 6f 72 79 49 6e 74 65 72 66 61 63 65      # "ctoryInterface"
  68                                               # Text string length 8
    4d 65 74 61 44 61 74 61                        # "MetaData"
  a1                                               # Map length 1
    64                                             # Text string length 4
      4b 65 79 73                                  # "Keys"
    82                                             # Array length 2
      67                                           # Text string length 7
        51 4d 59 53 51 4c 33                       # "QMYSQL3"
      66                                           # Text string length 6
        51 4d 59 53 51 4c                          # "QMYSQL"
  69                                               # Text string length 9
    63 6c 61 73 73 4e 61 6d 65                     # "className"
  72                                               # Text string length 18
    51 4d 59 53 51 4c 44 72 69 76 65 72 50 6c 75   # "QMYSQLDriverPlu"
    67 69 6e                                       # "gin"
  65                                               # Text string length 5
    64 65 62 75 67                                 # "debug"
  f5                                               # Simple Type true
  67                                               # Text string length 7
    76 65 72 73 69 6f 6e                           # "version"
  1a 00 05 0a 00                                   # Unsigned integer 0x50a00

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center






More information about the Development mailing list