Created
March 15, 2010 06:11
-
-
Save sprsquish/332574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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