Nanopb v0.4.4 Conflict

Hello!

I have a project that utilizes Nanopb for Protocol Buffers serializing of data. Currently, it seems that the Particle stdlib has Nanopb~0.3.9.3 included. This may be fore internal Particle communications (cloud functions), but it conflicts with with my project as I am using Nanopb~0.4.4

Ive tries to #include "pb.h" instead of #include <pb.h> in hopes that it would use the local version, but I havent been able to get the Particle Workbench (vscode) to grab the Nanopb files in the ./lib directory instead of the v0.3.9.3 in the stdlib.

I know there are major differences between the libraries, which will make it difficult to substitute one for the other. Any suggests for how to work around this issue?

I have made attempts to get around this issue by re-compiling my application (moving from Teensy to Electron) using the older version of Nanopb (v0.3.9.3).

This not been successful since the older version of Nanopb doesnt support optional fields in the proto files… Which I have utilized.

I have also tried dropping Nanopb-0.4.4 into the device OS github repo to see if the CI passed, but it failed (as I would expect for such a change) travis build

An even dumber approach, I replaced Nanopb-0.3.9.3 with Nanopb-0.4.4 in the DeviceOS toolchain for local compile (Particle Workbench). That obviously didn’t work either.

I don’t have enough understanding of the Particle build system to get around this issue.

My next step will be to try and isolate the Nanopb-0.4.4 into its own namespace and force both nanopb versions to exist in the compile :confused:

Temporary Fix

Thanks to the Nanopb folks being stellar C devs, it is easy to rename every symbol and preprocessor directive with a little regex.

Regex:
find: (pb_)
replace [leader]_$1
(Note: the search is case agnostic. Or just run with (pb_|PB_))

Where [leader] can be whatever you like, ex: MY for MY_pb_...
This replace needs to be run in the source files of your project, and any files that rely on Nanopb. Also run this in your generated NanoPB files (ex. my_file.pb.c my_file.pb.h)

Then, You also need to rename the headers and source files for the Nanobp files:
pb_common.cMY_pb_common.c
pb_common.hMY_pb_common.h
pb_decode.cMY_pb_decode.c
pb_decode.hMY_pb_decode.h
pb_encode.cMY_pb_encode.c
pb_encode.hMY_pb_encode.h
pb.hMY_pb.h

Make sure the includes of your files match the new names, and you should be good to go!
(You can fix the includes with easy search/replace as well)

1 Like