Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "server_protocol.pb-c.h"
- #define MAX_MSG_SIZE 1024 // 1K
- //
- int main(int argc, char *argv[]) {
- ServerProtocol msg = SERVER__PROTOCOL__INIT;
- void * buf;
- unsigned len;
- msg.command = "AUTH";
- msg.username = "Dashed";
- msg.password = "rofl23";
- // This is calculated packing length
- len = server__protocol__get_packed_size(&msg);
- // Allocated memory for packed/encode serialized data
- buf = malloc(len);
- server__protocol__pack(&msg,buf); // Put it in buf now
- fprintf(stderr,"Writing %d serialized bytes\n",len); // See the length of message
- printf("Sent: ");
- // Write to stdout to allow direct command line piping
- //fwrite(buf,len,1,stdout);
- printf("\n");
- // Free the allocated serialized buffer
- //free(buf);
- ////////////////////////////////////
- ServerProtocol *msg2;
- //uint8_t buf2[MAX_MSG_SIZE]; // Create a temporary buffer
- msg2 = server__protocol__unpack(NULL,len,buf); // Deserialize the serialized data
- printf("Received: command=%s username=%s password=%s table=%s key=%s value=%s\n",msg2->command, msg2->username, msg2->password, msg2->table, msg2->key, msg2->value);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement