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

Size of binary json representations #1919

Closed
davidglavas opened this issue Jan 30, 2020 · 2 comments
Closed

Size of binary json representations #1919

davidglavas opened this issue Jan 30, 2020 · 2 comments
Labels
aspect: binary formats BSON, CBOR, MessagePack, UBJSON kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@davidglavas
Copy link

davidglavas commented Jan 30, 2020

For the following example, is it correct to say that v_cbor.size() is the size (number of bytes) of the CBOR representation for the JSON document {"compact": true, "schema": 0}? I guess it's the same for the other binary formats in this library?

// create a JSON value
nlohmann::json j = R"({"compact": true, "schema": 0})"_json;

// serialize to CBOR
std::vector<std::uint8_t> v_cbor = nlohmann::json::to_cbor(j);

// 0xA2, 0x67, 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0xF5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x00

// roundtrip
nlohmann::json j_from_cbor = nlohmann::json::from_cbor(v_cbor);

std::cout << "CBOR:" << std::endl;
std::cout << j_from_cbor << std::endl;                                                     // print plaintext
std::cout << uint8_vector_to_hex_string(v_cbor) << std::endl;                               // print binary representation
std::cout << "Size (bytes) of binary representation: " << v_cbor.size() << std::endl;
std::cout << std::endl << std::endl;
@nlohmann
Copy link
Owner

Yes - the result of the binary formats is a vector of bytes, so size() is the right way to query the size.

@nlohmann nlohmann added aspect: binary formats BSON, CBOR, MessagePack, UBJSON solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jan 31, 2020
@stale
Copy link

stale bot commented Mar 1, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Mar 1, 2020
@stale stale bot closed this as completed Mar 8, 2020
@nlohmann nlohmann removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jul 25, 2020
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: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants