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

Add support for high-precision numbers in UBJSON encoding #2286

Closed
1 of 3 tasks
hahmadi opened this issue Jul 18, 2020 · 3 comments · Fixed by #2297
Closed
1 of 3 tasks

Add support for high-precision numbers in UBJSON encoding #2286

hahmadi opened this issue Jul 18, 2020 · 3 comments · Fixed by #2297
Assignees
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: enhancement/improvement release item: ⚡ improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@hahmadi
Copy link

hahmadi commented Jul 18, 2020

Feature Request

UBJSON is designed to support mapping from any JSON value. For numeric values specifically, it has a high-precision numeric value to represent any number: http://ubjson.org/?page_id=422#numeric

Currently nlohmann::json does not support that data type so users have to use other binary serialization formats. However, none of the other supported formats are as flexible as UBJSON in representing JSON values and have other limitations.

Can you provide a small but working code example?

json j1 = 11111111111111111111ULL;
auto v = json::to_ubjson(j1);
json j2 = json::from_ubjson(v);

What is the expected behavior?

Support storing uint64 numbers as high-precision numbers: http://ubjson.org/?page_id=422#numeric

And what is the actual behavior instead?

integer number 11111111111111111111 cannot be represented by UBJSON as it does not fit int64

Which version of the library did you use?

  • latest release version 3.7.3
  • other release - please state the version: ___
  • the develop branch
@nlohmann
Copy link
Owner

Thanks for reporting. I think serialization should be simple as we can rely on code from the JSON serializer for int-to-string conversion. The reverse (parsing) could be more challenging I shall have a look.

@nlohmann
Copy link
Owner

I opened a PR #2297 for this issue. Unfortunately, there is a SIGSEGV when running the tests with MSVC 2019. Any help on this would be greatly appreciated!

@nlohmann nlohmann added state: help needed the issue needs help to proceed and removed state: help needed the issue needs help to proceed labels Jul 21, 2020
@nlohmann nlohmann added this to the Release 3.8.1 milestone Jul 23, 2020
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation release item: ⚡ improvement labels Jul 24, 2020
@hahmadi
Copy link
Author

hahmadi commented Jul 26, 2020

Thank you for the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: enhancement/improvement release item: ⚡ improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants