Question about NanoPB decoder

48 views
Skip to first unread message

Hamza Hajeir

unread,
Aug 26, 2023, 6:30:06 PM8/26/23
to nanopb
Hi there,
Hope everyone is well!

I'm designing an IoT System and came across serialization, after some inquiries and searches found the NanoPB.

Diven a little in reading decoding code, it seems doesn't make a copy from the input stream and that's perfect!

My question is: Is it an implemented feature that a user can get a view of a string or bytes pointing to the input data? or there "must" happen a copy?

If so, is it enabled within the c++ wrapper (nanopb_cpp)?

Regards,
Hamza Hajeir

Petteri Aimonen

unread,
Aug 27, 2023, 1:11:46 AM8/27/23
to nan...@googlegroups.com
Hi,

> My question is: Is it an implemented feature that a user can get a view of
> a string or bytes pointing to the input data? or there "must" happen a copy?

I think my prior answer to you on StackOverflow covers this.
Providing a view to input buffer is not a built-in feature, but can be done
in user code using callbacks:
https://stackoverflow.com/questions/76945067/protobuf-to-parse-pre-allocated-data-and-output-without-copy/76950295

> If so, is it enabled within the c++ wrapper (nanopb_cpp)?

I haven't used nanopb_cpp, but I think the wrappers don't limit functionality in any way.

--
Petteri

Hamza Hajeir

unread,
Sep 13, 2023, 7:48:42 AM9/13/23
to nanopb
Hi Petteri,

Thanks for your quick response and handed support.

However, I've decided currently to go with protozero, as I think it's more suitable for my case currently.

As a feedback why, here's some reasons got me away from nanopb:
- Buffers should be statically provided beforehand (even though malloc option is available).
- To my understanding, nanopb encodes 2x times the same object, and if I want to calculate the needed buffer size in prior, I'd need another one.
- The perceived complexity of utilizing the library is high to me. 
- I'll prefer C++ always, but the complexity reaches the C++ wrapper too, and given the requirement (of getting a view of string/bytes at decoding), I really don't know whether I need to take a similar approach answered there (and what goes beyound that?), or it'll be solved directly within the wrapper.
- My use-case is simple, and it wont change as far as I can see, thus, the build serializers and parsers took me no more than a day.

Therefore I've postponed the adoption of protobuf-schema-aware library to the future.

Hope nanopb the best,
Hamza Hajeir  
Reply all
Reply to author
Forward
0 new messages