Sample snippet of code
KEY = (char *)malloc(sizeof(argRkMessage->key)+1);
if( KEY != NULL )
{
//Logger
}
reader_class = avro_generic_class_from_schema(KEYSchema);
check_i(avro_generic_value_new(reader_class, &val));
/*Send the memory in the buffer into the reader*/
nested_reader = avro_reader_memory( argRkMessage->key, sizeof(argRkMessage->key) );
check_i(avro_value_read( nested_reader, &val ));
type = avro_value_get_type(&val);
if ( type == AVRO_RECORD )
{
//logger
}
check_i(avro_value_get_size(&val, &field_count));
check_i(avro_value_get_by_name(&val, "Key", &field, NULL));
type = avro_value_get_type(&field);
if ( type == AVRO_STRING )
{
//logger
}
check_i(avro_value_get_string(&field, &KEY, &size));
printf(“Key is:%s", KEY);
The problem i have is "KEY" always comes to be a NULL string.
I did try a solution to do a hexdump of the contents of argRkMessage->key , that seems to have the value.
I am using librdkafka and avro.c to get this implemented. The sample code is a stripped down version of a C-Kafka consumer process that is intended to get complex Kafka messages encoded in AVRO format.