Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- syntax = "proto3";
- package learn;
- message learnmessage {
- enum LearnType {
- ZERO = 0;
- ONE = 1;
- TWO = 2;
- THREE = 3;
- FOUR = 4;
- FIVE = 5;
- SIX = 6;
- }
- LearnType typ = 1;
- string text = 2;
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include "learn.pb-c.h"
- int main()
- {
- Learn__Learnmessage msg = LEARN__LEARNMESSAGE__INIT, *msgCopy;
- size_t len;
- uint8_t *msgStr;
- msg.typ = LEARN__LEARNMESSAGE__LEARN_TYPE__THREE; //corresponds to enum value 3
- msg.text = "again";
- len = learn__learnmessage__get_packed_size(&msg); //get the length of the uint8_t needed to pack the message
- msgStr = malloc(len * sizeof(uint8_t));
- learn__learnmessage__pack(&msg, msgStr); //packs the message into msgStr
- msgCopy = learn__learnmessage__unpack(NULL, len, msgStr); //unpack the message into msgCopy
- printf("Orginal: %d n", msg.typ); //prints 3 (expected)
- printf("Copy: %d n", msgCopy->typ); //prints 0 (un-expected)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement