Skip to content

Instantly share code, notes, and snippets.

@sprsquish
Created March 15, 2010 06:11
Show Gist options
  • Select an option

  • Save sprsquish/332574 to your computer and use it in GitHub Desktop.

Select an option

Save sprsquish/332574 to your computer and use it in GitHub Desktop.
#include <avro.h>
#include <stdio.h>
#include <stdlib.h>
#define PERSON_SCHEMA \
"{\"type\":\"record\",\
\"name\":\"Person\",\
\"fields\":[\
{\"name\": \"ID\", \"type\": \"long\"},\
{\"name\": \"First\", \"type\": \"string\"},\
{\"name\": \"Last\", \"type\": \"string\"},\
{\"name\": \"Phone\", \"type\": \"string\"},\
{\"name\": \"Age\", \"type\": \"int\"}]}"
int main(void) {
printf(PERSON_SCHEMA"\n\n");
avro_schema_t person_schema;
avro_schema_error_t error;
if (avro_schema_from_json(PERSON_SCHEMA, sizeof(PERSON_SCHEMA),
&person_schema, &error)) {
fprintf(stderr, "Unable to parse person schema\n");
exit(EXIT_FAILURE);
}
char buffer[sizeof(PERSON_SCHEMA)];
avro_writer_t person_writer = avro_writer_memory(buffer, sizeof(PERSON_SCHEMA));
avro_schema_to_json(person_schema, person_writer);
printf("%s\n\n", buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment