问题
I am writing a php script using avro to deserialize data. I receive the data as a buffer of avro binary stream. In the avro php example, I see only an example of reading the data from a file. not a binary buffer.
How can I deserialize the data? What I am looking for is a binary decoder for avro
回答1:
$binaryBuffer = <get_avro_serialized_record>
$writersSchema = '{
"type" : "record",
"name" : "Example",
"namespace" : "com.example.record",
"fields" : [ {
"name" : "userId",
"type" : "int"
.............
}'
$reader = new AvroIODatumReader($writersSchema);
$io = new AvroStringIO($binaryBuffer)
$deserializedRecord = $reader->read(new AvroIOBinaryDecoder($io))
assuming you want to deserialize each record separately, and have the writers schema.
来源:https://stackoverflow.com/questions/36765190/avro-php-reading-from-buffer