Skip to content

Instantly share code, notes, and snippets.

@brianmario
Created November 4, 2017 23:44
Show Gist options
  • Save brianmario/a33400a6bb3e957ad798c232ae4b1a4f to your computer and use it in GitHub Desktop.
Save brianmario/a33400a6bb3e957ad798c232ae4b1a4f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h>
static int yajl_found_null(void* ctx) {
(void)ctx;
fprintf(stdout, "yajl_found_null\n");
return 1;
}
static int yajl_found_boolean(void* ctx, int boolean) {
(void)ctx;
(void)boolean;
fprintf(stdout, "yajl_found_boolean\n");
return 1;
}
static int yajl_found_integer(void * ctx, long val) {
(void)ctx;
(void)val;
fprintf(stdout, "yajl_found_integer\n");
return 1;
}
static int yajl_found_double(void* ctx, double val) {
(void)ctx;
(void)val;
fprintf(stdout, "yajl_found_double\n");
return 1;
}
static int yajl_found_number(void* ctx, const char* val, unsigned int len) {
(void)ctx;
(void)val;
(void)len;
fprintf(stdout, "yajl_found_number\n");
return 1;
}
static int yajl_found_string(void* ctx, const unsigned char* val, unsigned int len) {
(void)ctx;
(void)val;
(void)len;
fprintf(stdout, "yajl_found_string\n");
return 1;
}
static int yajl_found_map_key(void* ctx, const unsigned char* val, unsigned int len) {
(void)ctx;
(void)val;
(void)len;
fprintf(stdout, "yajl_found_map_key\n");
return 1;
}
static int yajl_found_start_map(void* ctx) {
(void)ctx;
fprintf(stdout, "yajl_found_start_map\n");
return 1;
}
static int yajl_found_end_map(void* ctx) {
(void)ctx;
fprintf(stdout, "yajl_found_end_map\n");
return 1;
}
static int yajl_found_start_array(void* ctx) {
(void)ctx;
fprintf(stdout, "yajl_found_start_array\n");
return 1;
}
static int yajl_found_end_array(void* ctx) {
(void)ctx;
fprintf(stdout, "yajl_found_end_array\n");
return 1;
}
static yajl_callbacks callbacks = {
yajl_found_null,
yajl_found_boolean,
yajl_found_integer,
yajl_found_double,
yajl_found_number,
yajl_found_string,
yajl_found_start_map,
yajl_found_map_key,
yajl_found_end_map,
yajl_found_start_array,
yajl_found_end_array
};
int main() {
yajl_handle parser;
parser = yajl_alloc(&callbacks, NULL, NULL, NULL);
unsigned char buf[1024*32];
size_t nread;
nread = fread(&buf[0], 1, sizeof(buf), stdin);
yajl_status rc;
fprintf(stdout, "input: %.*s\n", (int)nread, &buf[0]);
rc = yajl_parse(parser, &buf[0], (unsigned int)nread);
yajl_free(parser);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment