Follow up question on named records:
If a record refers to itself without using a union-type, this leads to
infinite recursion, so it's impossible to serialize the data.
(e.g.)
{
"type": "record",
"name": "LongList",
"fields" : [
{"name": "value", "type": "long"},
{"name": "next", "type": "LongList"}
]
}
Does the spec or the implementation(s) do anything to address such cases?
thanks,
Scott
Sharad Agarwal wrote:
Scott Banachowski wrote:
Is the scope of the record only for the current record?
No. All types and messages which are part of the same protocol definition
file can refer to the record by name.
Or, for example, if I had an record that defined 2 fields, each a
record, could record 2 refer to record 1 by name? And vise-versa (i.e.
can we forward reference types not yet defined)?
Forward referencing is not allowed.
{
"type": "record",
"name": "longlist",
"fields" : {
"nested1" : {
"type" : "record",
"name" : "rec1",
"fields" : {
"a":"long",
"b": "rec2" /* LEGAL? to refer to rec2? */
}
}
}
"nested2" : {
"type" : "record",
"name" : "rec2",
"fields" : {
"c":"long",
"d": "rec1" /* LEGAL? to refer to rec1? */
}
}
"contrived" : ["longlist", "rec1", "rec2"] /* LEGAL? */
}
}
rec1 can't refer to rec2. However other way is legal.
Also, can named fields also be referred to as types in other fields?
{
"type": "record",
"name": "longlist",
"fields" : {
"value" : "long",
"next" : ["longlist", "null"],
"likenext" : "next" /* LEGAL? to refer to next as type? */
}
}
Not Legal. "next" here is field identifier, not a type.
- Sharad