Beispiel #1
0
static void output_avro_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
        bool is_init) {
    plugin_state *state = palloc(sizeof(plugin_state));
    ctx->output_plugin_private = state;
    opt->output_type = OUTPUT_PLUGIN_BINARY_OUTPUT;

    state->memctx = AllocSetContextCreate(ctx->context, "Avro decoder context",
            ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE);

    state->frame_schema = schema_for_frame();
    state->frame_iface = avro_generic_class_from_schema(state->frame_schema);
    avro_generic_value_new(state->frame_iface, &state->frame_value);
    state->schema_cache = schema_cache_new(ctx->context);
}
frame_reader_t frame_reader_new() {
    frame_reader_t reader = malloc(sizeof(frame_reader));
    check_alloc(reader);
    memset(reader, 0, sizeof(frame_reader));
    reader->num_schemas = 0;
    reader->capacity = 16;
    reader->schemas = malloc(reader->capacity * sizeof(void*));
    check_alloc(reader->schemas);

    reader->frame_schema = schema_for_frame();
    reader->frame_iface = avro_generic_class_from_schema(reader->frame_schema);
    avro_generic_value_new(reader->frame_iface, &reader->frame_value);
    reader->avro_reader = avro_reader_memory(NULL, 0);
    return reader;
}