50 lines
1.5 KiB
C
50 lines
1.5 KiB
C
|
|
#include <sys/stat.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
#include "empack.h"
|
||
|
|
|
||
|
|
#define USAGE \
|
||
|
|
"empack_cli [OPTIONS] <file | msgpack hex>\r\n" \
|
||
|
|
" file: File to read binary Msgpack data from, \"-\" for stdin\r\n" \
|
||
|
|
" msgpack hex: Hex string of Msgpack data\r\n" \
|
||
|
|
"\r\n" \
|
||
|
|
"OPTIONS\r\n" \
|
||
|
|
" -h/--help: Print this message\r\n"
|
||
|
|
|
||
|
|
static void
|
||
|
|
print_func(const char *buf, uint32_t buflen, void *arg)
|
||
|
|
{
|
||
|
|
printf("%.*s", buflen, buf);
|
||
|
|
}
|
||
|
|
|
||
|
|
int
|
||
|
|
main(int argc, char **argv)
|
||
|
|
{
|
||
|
|
const uint8_t input[] = { 0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00 };
|
||
|
|
size_t input_len = sizeof(input);
|
||
|
|
empack_t empack;
|
||
|
|
uint8_t arena[256];
|
||
|
|
uint32_t chars_printed;
|
||
|
|
|
||
|
|
empack_init(&empack, arena, sizeof(arena));
|
||
|
|
|
||
|
|
if (empack_parse(&empack, input, input_len)) {
|
||
|
|
fprintf(stderr, "Parsing error\r\n");
|
||
|
|
return (-1);
|
||
|
|
}
|
||
|
|
|
||
|
|
chars_printed = empack_print(&empack, print_func, NULL, " ");
|
||
|
|
printf("\r\n-- Stats --\r\n"
|
||
|
|
"Characters Printed: %u\r\n"
|
||
|
|
"Arena Memory Used: %u/%uB (%u%%)\r\n"
|
||
|
|
"-----------\r\n",
|
||
|
|
chars_printed,
|
||
|
|
empack.arena_used,
|
||
|
|
empack.arena_sz,
|
||
|
|
(empack.arena_used * 100) / empack.arena_sz);
|
||
|
|
|
||
|
|
return (0);
|
||
|
|
}
|