-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help with libserdes example program #32
Comments
I was wondering about this example the other day. The example encodes the input as a string https://github.com/confluentinc/libserdes/blob/master/examples/serdes-kafka-avro-client.c#L215, using the schema only to populate the magic byte. Maybe you should input just the values: https://avro.apache.org/docs/current/spec.html#binary_encoding maybe instead of: try: I don't know how to handle that MSRP being an "int", but supplied as a string. |
I truly don't understand the value in shipping example code which does not work out of the box. I believe there is a shortcoming in the libserdes and in the example code. It's missing the functionality to convert json to avro - both in the example code and in the lib itself. Surprisingly enough, libserdes does have the code to do the reverse i.e. avro to json! Go figure! The right way to fix it would be to add functionality in libserdes to convert from json to avro, and then the example code should be modified to call that functionality. For my purposes, I coded a function to convert from json to avro in example code, and then it all worked. |
Here are the 2 functions that I added to convert from json to avro. I simply called json_to_avro() from run_producer() after `int schema_traverse(const avro_schema_t schema, json_t *json,
} void json_to_avro(char *buffer, int buffer_len, avro_schema_t schema, avro_value_t *val)
}` |
This sounds great. I'll going to try out your code. |
I can't get it together properly. Your code uses a avro_schema_t but we are given a serdes_schema_t. Where did you get the avro_schema_t for the call to json_to_avro? |
Here is how you do it: ` #if 0 |
Yes, that's good. You should get a PR going for this. |
It works. Thanks much. At the moment running into issue with supporting ENUM types in avro schema. I noticed it keeps returning the first item as it lacks the implementation in the following case statement (schema_traverse routine). case AVRO_ENUM: Could anyone get AVRO_ENUM to work at some point? If so, please post that part of the code. I am trying out few things too to get AVRO_ENUM case block working and will post my response here. Thanks. |
Got it working. Here is the snippet.
|
I'm trying to use the ./serdes-kafka-avro-client example as shipped with latest version of libserdes, but I cannot get it to work. Could someone please let me know if it's working code or not? Or maybe I'm not using it as intended. Here's my output:
1). The schema is already registered in schemaregistry:
curl -X GET localhost:60002/subjects/car/versions/latest | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 258 100 258 0 0 15246 0 --:--:-- --:--:-- --:--:-- 16125
{
"subject": "car",
"version": 1,
"id": 22,
"schema": "{"type":"record","name":"Car","fields":[{"name":"Make","type":"string"},{"name":"Model","type":"string"},{"name":"Year","type":"string"},{"name":"MSRP","type":"int"}]}"
}
I start the consumer
./serdes-kafka-avro-client -C -b localhost:60000 -t aamir -p 0 -r localhost:60002
I start the producer
./serdes-kafka-avro-client -P -b localhost:60000 -t aamir -r localhost:60002 -s 22
% Using schema (null) with id 22
% Use "schema: " to specify a new schema
% Use "str: " to produce an Avro-encoded string
% Ctrl-D to exit
I enter just one record from producer
str: {"Make":"BMW","Model":"M-4","Year":"2014","MSRP":55000}
The consumer complains that it cannot deserialize
% serdes_deserialize_avro failed: Failed to read avro value: Cannot read string value: Cannot read string length: Cannot read 1 bytes from memory bufferCannot read string value: Cannot read string length: Cannot read 1 bytes from memory bufferCannot read string value: Cannot read string length: Cannot read 1 bytes from memory bufferCannot read string value: Cannot read string length: Cannot read 1 bytes from memory bufferCannot read string value: Cannot read string length: Cannot read 1 bytes from memory bufferCannot read string value: Can
Can someone please help?
Thanks!
The text was updated successfully, but these errors were encountered: