Created
March 19, 2010 21:40
-
-
Save waywardmonkeys/338223 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
| // a GenAvro file might look like: | |
| // @namespace("wwm") | |
| record timestamp { | |
| long seconds; | |
| long nanoseconds; | |
| } | |
| // @namespace("wwm") | |
| record something { | |
| string whatever; | |
| } | |
| // @namespace("wwm") | |
| record lock_activity { | |
| timestamp timestamp; | |
| long lockID; | |
| array<something> foo; | |
| } | |
| /* | |
| That'll generate at least these files: | |
| * wwm_types.h | |
| * wwm_types_read.c | |
| * wwm_types_read_template.i | |
| * wwm_types_size.c | |
| * wwm_types_size_template.i | |
| * wwm_types_skip.c | |
| * wwm_types_skip_template.i | |
| * wwm_types_write.c | |
| * wwm_types_write_template.i | |
| wwm_types_write.c would look like: | |
| */ | |
| #define AVRO_ENCODE(NAMESPACE, TYPE) NAMESPACE ## _encode_ ## TYPE ## _binary | |
| #include "wwm_types_write_template.i" | |
| #undef AVRO_ENCODE | |
| #define AVRO_ENCODE(NAMESPACE, TYPE) NAMESPACE ## _encode_ ## TYPE ## _json | |
| #include "wwm_types_write_template.i" | |
| #undef AVRO_ENCODE | |
| /* | |
| wwm_types_write_template.i would look like: | |
| */ | |
| int AVRO_ENCODE(wwm, timestamp)(avro_writer_t writer, wwm_timestamp_t * this) | |
| { | |
| BEGIN_ENCODER; | |
| CHECK(AVRO_ENCODE(avro, long)(writer, this->seconds)); | |
| CHECK(AVRO_ENCODE(avro, long)(writer, this->nanoseconds)); | |
| return 0; | |
| HANDLE_ERROR; | |
| } | |
| int AVRO_ENCODE(wwm, something)(avro_writer_t writer, wwm_something_t * this) | |
| { | |
| BEGIN_ENCODER; | |
| CHECK(AVRO_ENCODE(avro, string)(writer, this->whatever)); | |
| return 0; | |
| HANDLE_ERROR; | |
| } | |
| int AVRO_ENCODE(wwm, lock_activity)(avro_writer_t writer, wwm_lock_activity * this) | |
| { | |
| BEGIN_ENCODER; | |
| CHECK(AVRO_ENCODE(wwm, timestamp)(this->timestamp, writer)); | |
| CHECK(AVRO_ENCODE(avro, long)(writer, this->lockID)); | |
| CHECK(AVRO_ENCODE(avro, array_begin)(writer, this->foo_count)); | |
| for (int idx = 0; idx < this->foo_count; idx++) { | |
| CHECK(AVRO_ENCODE(wwm, something)(writer, this->foos[idx])); | |
| } | |
| CHECK(AVRO_ENCODE(avro, array_end)(writer)); | |
| return 0; | |
| HANDLE_ERROR; | |
| } | |
| /* | |
| And some of the utility stuff there would be defined as: | |
| */ | |
| #define BEGIN_ENCODER int rval | |
| #define CHECK(INVOCATION) rval = INVOCATION; if (rval != 0) goto handle_error; | |
| #define HANDLE_ERROR handle_error: return rval; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment