avro 中的重复字段 (python)

repeating fields in avro (python)

我正在尝试在 python 中使用 avro 来序列化 XML 数据。我可以弄清楚可选的字段编码,但是我该如何处理重复的字段?

例如,给定此模式,我如何使 favorite_number 成为一个重复字段,以便某人可以拥有多个 favorite_number?

{"namespace": "example.avro",
 "type": "record",
 "name": "User",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": "int"},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}

来自 specification,可能是这样的...

# For example, a linked-list of 64-bit values may be defined with:

{
   "type": "record", 
   "name": "LongList",
   "aliases": ["LinkedLongs"],                      // old name for this
   "fields" : [
       {"name": "value", "type": "long"},             // each element has a long
       {"name": "next", "type": ["LongList", "null"]} // optional next element
   ]
}

或者您可以使用数组...

# Arrays use the type name "array" and support a single attribute:
#
# items: the schema of the array's items.
# For example, an array of strings is declared with:

{"type": "array", "items": "int"}

此外,您可以嵌套记录 like so