1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <pb_encode.h> 5 #include <pb_decode.h> 6 #include "fixed_array.pb.h" 7 #include "unittests.h" 8 main(int argc,char ** argv)9int main(int argc, char **argv) 10 { 11 int status = 0; 12 uint8_t buffer[64]; 13 pb_size_t msglen = 0; 14 15 { 16 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 17 MainMessage msg = MainMessage_init_zero; 18 19 msg.submsg.data[0] = 0; 20 msg.submsg.data[4] = 5; 21 22 TEST(pb_encode(&stream, MainMessage_fields, &msg)); 23 24 msglen = stream.bytes_written; 25 TEST(msglen > 5); 26 } 27 28 { 29 pb_istream_t stream = pb_istream_from_buffer(buffer, msglen); 30 MainMessage msg = MainMessage_init_zero; 31 32 TEST(pb_decode(&stream, MainMessage_fields, &msg)); 33 34 TEST(msg.submsg.data[0] == 0); 35 TEST(msg.submsg.data[4] == 5); 36 } 37 38 return status; 39 } 40 41