2016-09-14 23:05:02 +02:00
|
|
|
#include "../lib/pubsubd.h"
|
2016-09-17 22:57:32 +02:00
|
|
|
#include <cbor.h>
|
2016-09-14 23:05:02 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-15 23:08:08 +02:00
|
|
|
#define PKT_CLOSE 0
|
|
|
|
#define PKT_MSG 1
|
|
|
|
#define PKT_ERROR 2
|
|
|
|
|
2016-09-14 23:05:02 +02:00
|
|
|
void
|
2018-11-02 21:03:54 +01:00
|
|
|
ohshit(int32_t rvalue, const char* str) {
|
2016-09-14 23:05:02 +02:00
|
|
|
fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
|
|
|
|
exit (rvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void usage (char **argv)
|
|
|
|
{
|
|
|
|
printf ( "NOT DONE YET\n");
|
|
|
|
printf ( "usage: %s [type [param]]...\n", argv[0]);
|
|
|
|
printf ( "ex: echo data | %s char_t 1\n", argv[0]);
|
|
|
|
printf ( " This sends a CBOR msg [ 1, \"data\" ]\n");
|
|
|
|
}
|
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t
|
|
|
|
main(int32_t argc, char **argv)
|
2016-09-14 23:05:02 +02:00
|
|
|
{
|
|
|
|
if (argc == 2 && strcmp ("-h", argv[1]) == 0) {
|
|
|
|
usage (argv);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
uint8_t buf[BUFSIZ];
|
2016-09-15 23:08:08 +02:00
|
|
|
memset (buf, 0, BUFSIZ);
|
|
|
|
|
|
|
|
ssize_t buflen = read (0, buf, BUFSIZ);
|
|
|
|
|
|
|
|
/* Preallocate the map structure */
|
|
|
|
cbor_item_t * root = cbor_new_definite_map(1);
|
|
|
|
/* Add the content */
|
|
|
|
cbor_map_add(root, (struct cbor_pair) {
|
|
|
|
.key = cbor_move(cbor_build_uint8(PKT_MSG)),
|
|
|
|
.value = cbor_move(cbor_build_bytestring(buf, buflen))
|
|
|
|
});
|
|
|
|
/* Output: `length` bytes of data in the `buffer` */
|
2018-11-02 21:03:54 +01:00
|
|
|
uint8_t * buffer;
|
2016-09-15 23:08:08 +02:00
|
|
|
size_t buffer_size, length = cbor_serialize_alloc (root, &buffer, &buffer_size);
|
|
|
|
|
|
|
|
fwrite(buffer, 1, length, stdout);
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
cbor_decref(&root);
|
|
|
|
|
2016-09-14 23:05:02 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|