在python 2.7中,使用Avro,我想将一个对象编码为一个字节数组.
我发现的所有示例都写入文件.
我尝试过使用io.BytesIO(),但这给出了:
AttributeError: '_io.BytesIO' object has no attribute 'write_long'
Run Code Online (Sandbox Code Playgroud)
使用io.BytesIO的示例
def avro_encode(raw, schema):
writer = DatumWriter(schema)
avro_buffer = io.BytesIO()
writer.write(raw, avro_buffer)
return avro_buffer.getvalue()
Run Code Online (Sandbox Code Playgroud)