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

enhanced reading #4

Open
kroggen opened this issue Jan 24, 2017 · 1 comment
Open

enhanced reading #4

kroggen opened this issue Jan 24, 2017 · 1 comment

Comments

@kroggen
Copy link

kroggen commented Jan 24, 2017

Hi!

Thank you for sharing your code!

I understand that netstrings are used mainly as lists, so I thought that we could enhance the sequential reading of strings in a netstring list.

In the current code we don't know how much remaining bytes are there to call netstring_read again. Off course we can calculate it but I guess that less code is better.

I forked the repo and made some changes. With it we can iterate a list with code like this:

while(netstring_read(&base, &size, &str, &len) == 0) {
  do_something(str, len);
}

If you think it is useful I can make a pull request.

It will break the current ABI, so it can have a new version.

Thank you again!

@kroggen
Copy link
Author

kroggen commented Jan 24, 2017

Now I added the netstring_add function. It supports adding many strings to a netstring list (it concatenates them).

 char *netstring=0;  /* we must initialize it to zero */

 netstring_add(&netstring, "first");
 netstring_add(&netstring, "second");
 netstring_add(&netstring, "third");

I guess it is better than using netstring_encode_new because with this one we have to concatenate the result by ourselves.

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

1 participant