2016-04-21 159 views
1

我正在写一个使用avro反序列化数据的php脚本。 我接收数据作为avro二进制流的缓冲区。 在avro php的例子中,我只看到一个从文件中读取数据的例子。不是二进制缓冲区。avro php - 从缓冲区读取

如何反序列化数据? 我所寻找的是Avro的

回答

0
$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)) 

假设你想单独反序列化的每个记录,并有作家架构的二进制译码器。