Sergei G / Mbed OS ProtocBufTest

Dependencies:   nanopb protocol

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "pb_decode.h"
00004 #include "sample.pb.h"
00005 
00006 int main()
00007 {
00008     printf("\nProtoBufTest\n");
00009     
00010     uint8_t buffer[2] = { 0x10, 0x05 };
00011     size_t message_length = 2;
00012     
00013     protocol_Sample message = protocol_Sample_init_zero;
00014     pb_istream_t stream = pb_istream_from_buffer(buffer, message_length);
00015     bool status = pb_decode(&stream, protocol_Sample_fields, &message);
00016     if (!status) {
00017         printf("Decoding failed: %s\n", PB_GET_ERROR(&stream));
00018         exit(1);
00019     }
00020     printf("Alarm: %d\n", message.alarm);
00021     
00022     exit(0);
00023 }