sample_python_avro.py 581 B

1234567891011121314151617181920212223
  1. from io import BytesIO
  2. from avro.schema import parse
  3. from avro.io import DatumReader, BinaryDecoder
  4. schema = parse("""{
  5. "namespace": "org.buildroot.package.python_avro",
  6. "type": "record",
  7. "name": "Developer",
  8. "fields": [
  9. {"name": "email", "type": "string"},
  10. {"name": "maintainer_of", "type": "string"}
  11. ]
  12. }""")
  13. example = b'<titouan.christophe@railnova.eu\x16python_avro'
  14. reader = DatumReader(schema)
  15. deserialized = reader.read(BinaryDecoder(BytesIO(example)))
  16. assert deserialized == {
  17. 'email': 'titouan.christophe@railnova.eu',
  18. 'maintainer_of': 'python_avro',
  19. }