Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: conversion from cjson to cbor #55

Closed
gretaromagnoli1993 opened this issue Jun 28, 2017 · 1 comment
Closed

error: conversion from cjson to cbor #55

gretaromagnoli1993 opened this issue Jun 28, 2017 · 1 comment
Labels

Comments

@gretaromagnoli1993
Copy link

I tried to test the example cjson2cbor.c. I used cjson.h from https://github.com/DaveGamble/cJSON
and I built the library into the project. If I run this example with the input json_example.cjson:

{
"a": [1, 2.2, -1, "žluťoučký kůň!!!"],
"b": {
"c": [true, false, null]
}
}

the corresponding output is:
?aa?@
??;vžluťoučký kůň!!!ab?ac????

but verifying with the tool cbor.me I expected something like this:

A2 # map(2)
61 # text(1)
61 # "a"
84 # array(4)
01 # unsigned(1)
FB 400199999999999A # primitive(4612136378390124954)
20 # negative(0)
76 # text(22)
C5BE6C75C5A56F75C48D6BC3BD206BC5AFC588212121 # "\xC5\xBElu\xC5\xA5ou\xC4\x8Dk\xC3\xBD k\xC5\xAF\xC5\x88!!!"
61 # text(1)
62 # "b"
A1 # map(1)
61 # text(1)
63 # "c"
83 # array(3)
F5 # primitive(21)
F4 # primitive(20)
F6 # primitive(22)

I note that the hexadecimal numbers are converted in ASCII. For example 61 = a
but A2 should be =ì instead of =?. Same error for 84 and many others numbers.

@PJK PJK added the bug label Jul 13, 2017
@PJK
Copy link
Owner

PJK commented Feb 19, 2023

The example executable outputs binary, not hex:

⇒  ./examples/cjson2cbor examples/data/json_example.json  | hexdump -C
00000000  a2 61 61 84 1b 00 00 00  00 00 00 00 01 fa 40 0c  |.aa...........@.|
00000010  cc cd 3b 00 00 00 00 00  00 00 00 76 c5 be 6c 75  |..;........v..lu|
00000020  c5 a5 6f 75 c4 8d 6b c3  bd 20 6b c5 af c5 88 21  |..ou..k.. k....!|
00000030  21 21 61 62 a1 61 63 83  f5 f4 f6                 |!!ab.ac....|
0000003b

This matches the expected encoding, up to the item length encoding width, which is automatically minimized by cbor.me but not by the example

@PJK PJK closed this as completed Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants