Reputation: 387
So I have an endpoint that accepts binary json content-type of vnd.kafka.binary.v1+json
I've created the avro object, but how do I format the data to properly call the endpoint?
envelope = Hash.new
# add some stuff to envelope hash
.....
envDatumWriter = Avro::IO::DatumWriter.new(envSchema)
envBuffer = StringIO.new
envEncoder = Avro::IO::BinaryEncoder.new(envBuffer)
envDatumWriter.write(envelope,envEncoder)
Should I just do this: envBuffer.string.to_json_raw_object
and post that to the endpoint?
Upvotes: 0
Views: 445
Reputation: 387
I was on the correct path. To send it to the endpoint just meant I had to do some extra things specific to the design on the endpoint. Base64 encoding for example as well as json.
envelope = Hash.new
# add some stuff to envelope hash
.....
env_datum_writer = Avro::IO::DatumWriter.new(env_schema)
env_buffer = StringIO.new("".force_encoding("BINARY"))
env_encoder = Avro::IO::BinaryEncoder.new(env_buffer)
env_datum_writer.write(envelope,env_encoder)
a = Base64.encode64(env_buffer.string.each_byte.to_a.join)
p_records = Hash.new
p_records["value"] = a
p_records_array = [p_records]
Upvotes: 1