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 binn_to_string() function #2

Open
fanoI opened this issue Jun 12, 2016 · 6 comments
Open

Add binn_to_string() function #2

fanoI opened this issue Jun 12, 2016 · 6 comments
Labels

Comments

@fanoI
Copy link

fanoI commented Jun 12, 2016

It is possible to add a function to dump the value of a binn in json like format?

The possible prototype could be:

const char *binn_to_string(void *data, size_t data_len);

I think it will be very important for debug purpose.

@kroggen
Copy link
Collaborator

kroggen commented Jun 12, 2016

Hi fanol!

Check the conversions/json folder. The functions for conversions are there.

You can use this function:

char * binn_to_json(void *binn);

The return value must be freed by the caller using free().

The conversion currently depends on jansson library. I tested with the version 2.3 but you can test with newer ones.

@fanoI
Copy link
Author

fanoI commented Jun 12, 2016

Yes I've noticed that but I think a dependency on jansson should be not needed! It should be an independent way to print the binn object to console what do you think?

@kroggen
Copy link
Collaborator

kroggen commented Jun 12, 2016

Currently the conversion code supports so export as import from JSON and also to/from jansson objects, what makes it useful for serialized data modifications.

This support may not be abandoned.

If you want you can implement a function to just export data as string without any deps as an alternative.

@fanoI
Copy link
Author

fanoI commented Jun 17, 2016

To be clear I don't intended to drop the conversion to json support but I think that should be an independent way to have have a toString() conversion without the need to:

  1. Convert the binn to a json_object
  2. Call the json_to_string() method
  3. Delete the created json
  4. Free the string itself after have printed it

The fact is that in my code we used json as Message format but now we are finding too much slow as we need to convert it in string to transmit the data and in reception to re-parse the data any time! With big json this could be really slow...

But at same time I find really useful to have the possibility for debug purposes to print the received data as string... now I'm asking myself if reconverting to string the binn to print it will defeat the purpose of binn: the string should be generated and allocated while the json library we use don't need to free the string when we do toString() onto a json_object so I imagine it retains a pointer to it will be faster or in the end nothing will change doing the conversion?

@kroggen
Copy link
Collaborator

kroggen commented Jun 17, 2016

Debug does not need to be fast! The current implementation is sufficient for debug purposes.

But if you want a different way, fork the project and make the function in the conversions/string folder.

@hbiblia
Copy link

hbiblia commented Oct 24, 2021

"binn_to_string" We should make this possible

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

3 participants