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

Set bytes_left in pb_stream_read #5

Open
floriaanpost opened this issue Mar 5, 2023 · 0 comments
Open

Set bytes_left in pb_stream_read #5

floriaanpost opened this issue Mar 5, 2023 · 0 comments

Comments

@floriaanpost
Copy link

Thank you for this library!

If found a small bug (at least for newer versions of nanopb) that is easily solvable.

stream->bytes_left should be set to 0 if the stream is empty (see https://jpa.kapsi.fi/nanopb/docs/concepts.html section Input streams). Currently you get an io error when parsing the stream.

The change below fixes this issue. I am not sure if you are still maintaining this package, but if you are I don't mind creating a pull request.

static bool pb_stream_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) {
    Stream *s = reinterpret_cast<Stream *>(stream->state);
    size_t read = s->readBytes(buf, count);
    if (read == 0)
        stream->bytes_left = 0;
    return read == count;
};
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