https://github.com/eric-wieser/nanopb-arduino
Arduino stream wrappers for nanopb
https://github.com/eric-wieser/nanopb-arduino
arduino nanopb platformio
Last synced: 8 months ago
JSON representation
Arduino stream wrappers for nanopb
- Host: GitHub
- URL: https://github.com/eric-wieser/nanopb-arduino
- Owner: eric-wieser
- Created: 2017-01-01T22:13:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-12-17T00:48:59.000Z (about 6 years ago)
- Last Synced: 2025-03-28T00:41:54.377Z (9 months ago)
- Topics: arduino, nanopb, platformio
- Language: C++
- Homepage: https://platformio.org/lib/show/1385/nanopb-arduino
- Size: 3.91 KB
- Stars: 43
- Watchers: 1
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
nanopb-arduino
==============
A simple [PlatformIO](https://platformio.org/) library for wrapping Arduino's [`Stream`](https://www.arduino.cc/en/Reference/Stream) and `Print` objects into [Nanopb](https://koti.kapsi.fi/jpa/nanopb/)'s `pb_istream_s` and `pb_ostream_s`.
Exposes two functions that do exactly what you'd expect:
* `pb_istream_s as_pb_istream(Stream& p)`
* `pb_ostream_s as_pb_ostream(Print& p)`
In most cases, all you'll need is:
```c++
#include
pb_istream_s pb_in = as_pb_istream(Serial);
pb_ostream_s pb_out = as_pb_ostream(Serial);
```
and then use `pb_encode(&pb_out, ...)` and `pb_decode(&pb_in)`.
This isn't restricted to [`Serial`](https://www.arduino.cc/en/reference/serial), and will work for any object that implements
`Stream`, such as `File` (returned from [`SD.open`](https://www.arduino.cc/en/Reference/SDopen) and the ethernet [`Client`](https://www.arduino.cc/en/Reference/ClientConstructor).
---
This can be used on top of [PacketIO](https://github.com/eric-wieser/packet-io), with
```c++
#include
#include
#include
COBSStream cobs_in(Serial);
pb_istream_s pb_in = as_pb_istream(cobs_in);
COBSPrint cobs_out(Serial);
pb_ostream_s pb_out = as_pb_ostream(cobs_out);
```
and then calling `cobs_out.end()` after each `pb_encode`, and `cobs_in.next()` after each `pb_decode`.