confluentinc / libserdes

Avro Serialization/Deserialization C/C++ library with Confluent schema-registry support
Apache License 2.0
5 stars 64 forks source link

AVRO_ENUM data serialization failing #47

Closed bhuvanracham closed 2 years ago

bhuvanracham commented 2 years ago

After retrieving the symbol value (int) successfully and using avro_value_set_int(avro_value_t, json_int_t), libserdes producer is not writing it in a format that can be digested by the consumer (always returns the first symbol of enum set). Using a Java based producer to write the same enum is resulting in consumers getting the right enum symbol. Do anyone have AVRO_ENUM serialization working in avro-c interfaces on the producer side?

Code snippet that is not working as expected is as below.

            case AVRO_ENUM:
                    {
                        int  symbol_value;
                        symbol_value = avro_schema_enum_get_by_name(schema, json_string_value(json));
                         avro_value_set_int(current_val, symbol_value);
                    }

Thanks.

bhuvanracham commented 2 years ago

Got it working. "avro_value_set_enum" did the trick.

                    json_int_t symbol_value;
                    symbol_value = (json_int_t) avro_schema_enum_get_by_name(schema, json_string_value(json));
                    avro_value_set_enum(current_val, symbol_value);