avro php - reading from buffer

回眸只為那壹抹淺笑 提交于 2019-12-13 19:14:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!