2019-12-29 21:29:12 +01:00
|
|
|
from io import BytesIO
|
2022-05-14 17:05:28 +02:00
|
|
|
from avro.schema import parse
|
2019-12-29 21:29:12 +01:00
|
|
|
from avro.io import DatumReader, BinaryDecoder
|
|
|
|
|
2022-05-14 17:05:28 +02:00
|
|
|
schema = parse("""{
|
2019-12-29 21:29:12 +01:00
|
|
|
"namespace": "org.buildroot.package.python_avro",
|
|
|
|
"type": "record",
|
|
|
|
"name": "Developer",
|
|
|
|
"fields": [
|
|
|
|
{"name": "email", "type": "string"},
|
|
|
|
{"name": "maintainer_of", "type": "string"}
|
|
|
|
]
|
|
|
|
}""")
|
|
|
|
|
|
|
|
example = b'<titouan.christophe@railnova.eu\x16python_avro'
|
|
|
|
|
|
|
|
reader = DatumReader(schema)
|
|
|
|
deserialized = reader.read(BinaryDecoder(BytesIO(example)))
|
|
|
|
|
|
|
|
assert deserialized == {
|
|
|
|
'email': 'titouan.christophe@railnova.eu',
|
|
|
|
'maintainer_of': 'python_avro',
|
|
|
|
}
|