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

Hex in CBOR #89

Open
CodeOn-ArK opened this issue Jun 9, 2022 · 7 comments
Open

Hex in CBOR #89

CodeOn-ArK opened this issue Jun 9, 2022 · 7 comments

Comments

@CodeOn-ArK
Copy link

Hi there!
How to encode a JSON format as following:

{
"val1" : p,
"val2" : h'1234abcd'
}

Where the field val2 is associated with a hex data.
This doesn't seems to be a correct JSON format, however the web interface is able to convert it to the required CBOR format.
I am unable to use any of the python/JS libs to convert this to CBOR, however the web is able to do so.
What is the correct representation of this format where I want to send a hex value
Regards

@cabo
Copy link
Contributor

cabo commented Jun 9, 2022

The cbor.me website uses CBOR Diagnostic Notation (Section 8 of RFC 8949), which is an extended form of JSON to represent CBOR data items in a readable form. Another popular text form of JSON data is YAML.

It is not necessary to generate such a form to generate CBOR. In Python, you typically use Python notation to build a data item in memory and then convert it using one of the Python libraries, e.g., cbor2.

@CodeOn-ArK
Copy link
Author

CodeOn-ArK commented Jun 9, 2022

ok, but how do I encode something in hex? "val2" : h'1234abcd' this kind of thing, in any language

@cabo
Copy link
Contributor

cabo commented Jun 9, 2022

That is a question about your programming language. In Python, there are byte strings in the form of "bytes objects", https://docs.python.org/3/library/stdtypes.html#typebytes. bytes.fromhex('1234abcd') should give you what you need. (I'm not an active Python programmer, I hope I got this right.)

@CodeOn-ArK
Copy link
Author

CodeOn-ArK commented Jun 9, 2022

Any possible implementation for node js.
Also, is the source for the website is available somewhere?

@cabo
Copy link
Contributor

cabo commented Jun 9, 2022

I'm not fluid in nodejs.
The https://cbor.me website is based on the cbor-diag gem, which you can find at https://github.com/cabo/cbor-diag.

@AtigPurohit
Copy link

AtigPurohit commented Jun 9, 2022

can we use cbor diagnostic notations with that library to encode hex
If yes how and any supporting materials for that

@cabo
Copy link
Contributor

cabo commented Jun 12, 2022

As the README says:

No documentation; use the source, for now (the above command line utilities should show the basic usage).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants