Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/pubsub/tests/msg.c

57 lines
1.2 KiB
C
Raw Normal View History

2017-01-19 22:07:52 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../lib/msg.h"
#include "../../core/error.h"
#include "../../core/utils.h"
#define CHAN "chan1"
#define DATA "hello chan1"
int main(int argc, char * argv[])
{
argc = argc;
argv = argv;
struct pubsub_msg msg;
memset (&msg, 0, sizeof (struct pubsub_msg));
msg.type = 8;
msg.chanlen = strlen (CHAN) + 1;
msg.chan = malloc (msg.chanlen);
memset (msg.chan, 0, msg.chanlen);
memcpy (msg.chan, CHAN, msg.chanlen);
msg.datalen = strlen (DATA) + 1;
msg.data = malloc (msg.datalen);
memset (msg.data, 0, msg.datalen);
memcpy (msg.data, DATA, msg.datalen);
printf ("msg 1: ");
pubsub_msg_print (&msg);
char *buffer = NULL;
size_t len = 0;
pubsub_msg_serialize (&msg, &buffer, &len);
mprint_hexa ("buffer msg 1", (unsigned char *) buffer, len);
struct pubsub_msg msg2;
memset (&msg2, 0, sizeof (struct pubsub_msg));
pubsub_msg_unserialize (&msg2, buffer, len);
printf ("msg 2: ");
pubsub_msg_print (&msg2);
pubsub_msg_free (&msg);
pubsub_msg_free (&msg2);
if (buffer != NULL)
free (buffer);
return EXIT_SUCCESS;
}