All in one solution demonstrating how to use nanopb Protocol Buffers library from within mbed environment. Test case is very simple. It works.
Original import was an all-in-one solution that only depends on mbed.
Current implementation extracted 2 librarires:
1) nanopb contains code required to use nanopb and Timestamp dependency. 2) protocol is a specific research protocol used by LCE at Itron at the moment of commit.
The application decodes Protocol Buffers message generated with GO application using the same 'protocol'. This test level application decodes message and validates that it matches expected.
It is simply a proof that nanopb library can be used.
source/main.cpp
- Committer:
- sgnezdov
- Date:
- 2017-07-12
- Revision:
- 0:fbdd0d307c19
File content as of revision 0:fbdd0d307c19:
#include "mbed.h" #include "pb_decode.h" #include "sample.pb.h" int main() { printf("\nProtoBufTest\n"); uint8_t buffer[2] = { 0x10, 0x05 }; size_t message_length = 2; protocol_Sample message = protocol_Sample_init_zero; pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); bool status = pb_decode(&stream, protocol_Sample_fields, &message); if (!status) { printf("Decoding failed: %s\n", PB_GET_ERROR(&stream)); exit(1); } printf("Alarm: %d\n", message.alarm); exit(0); }