在 ruby 中写入 Avro 并在 Python 中读取
Write Avro in ruby and read in Python
我在尝试将 Ruby 中写入的 Avro 字节解码为 Kafka 主题时遇到问题。在观察 avro 字节串时,我发现它看起来不错。但是当我尝试解码时,我得到一个“UnicodeDecodeError:'utf8' codec can't decode byte 0x98 in position 32: invalid start byte”。
import avro.schema
import avro.io
import io
bytes_reader = io.BytesIO(m.value)
decoder = avro.io.BinaryDecoder(bytes_reader)
reader = avro.io.DatumReader(schema)
print reader.read(decoder)
谢谢。
这样修改代码解决了问题
bytes_reader = io.BytesIO(msg.value)
reader = DataFileReader(bytes_reader, DatumReader())
for r in reader:
print r
我在尝试将 Ruby 中写入的 Avro 字节解码为 Kafka 主题时遇到问题。在观察 avro 字节串时,我发现它看起来不错。但是当我尝试解码时,我得到一个“UnicodeDecodeError:'utf8' codec can't decode byte 0x98 in position 32: invalid start byte”。
import avro.schema
import avro.io
import io
bytes_reader = io.BytesIO(m.value)
decoder = avro.io.BinaryDecoder(bytes_reader)
reader = avro.io.DatumReader(schema)
print reader.read(decoder)
谢谢。
这样修改代码解决了问题
bytes_reader = io.BytesIO(msg.value)
reader = DataFileReader(bytes_reader, DatumReader())
for r in reader:
print r