Alright, to all: The reason why rvalue was empty was because 'a' field was not set in my code (and for a record both need to be set) Thanks!
Confusing docs, but well worth the pain. Regards Saptarshi ----- Original Message ----- > From: "Saptarshi Guha" <[email protected]> > To: [email protected] > Sent: Wednesday, July 11, 2012 1:18:35 AM > Subject: Re: Adding array elements to record in a union > > As a follow up, avro_json of field_c displays the content 'v' e.g. > > { > "int": { > "v": [ > 2, > 1, > 5 > ] > } > } > > > but i'd rather get (rvalue) > { > "c": > { > "int": { > "v": [ > 2, > 1, > 5 > ] > } > } > } > > ----- Original Message ----- > > From: "Saptarshi Guha" <[email protected]> > > To: "avro" <[email protected]> > > Sent: Wednesday, July 11, 2012 12:53:41 AM > > Subject: Adding array elements to record in a union > > > > Hello, > > > > Below is the avro file. I'm trying to write an object of the form > > { > > "c": {"name":"int",....} > > } > > > > Here's how i go about it > > > > // aschema contains the schema for [1] > > avro_value_iface_t *robject_iface = > > avro_generic_class_from_schema(*aschema); > > avro_value_t rvalue,field_c,branch,branch_v; > > // New container, and go to element "c" (ie. index==1) > > avro_generic_value_new(robject_iface, &rvalue); > > avro_value_get_by_index(&rvalue, 1, &field_c, NULL); > > // No go into discriminant == 1 (integers) > > avro_value_set_branch(&field_c,1,&branch); > > // This is a record, so access it's 'v' field > > avro_value_get_by_index(&branch,0,&branch_v,NULL); > > for(int i=0;i < LENGTH; i++){ > > avro_value_t element; > > size_t new_index; > > avro_value_append(&branch_v, &element, &new_index); > > avro_value_set_int(&element,robj[i]); > > } > > > > As expected, branch_v when displayed as JSON shows [1,2,3 ...] > > (contents of robj) > > But the JSON of rvalue is empty ... (and it's size > > 'avro_value_sizeof' is 0). > > > > What am i doing wrong? > > > > Regards > > Saptarshi > > Avro 1.7 > > > > [1] > > { > > "namespace": "robjects.avro", > > "type": "record", > > "name": "robject", > > "fields": [ > > {"name":"a" ,"type":["null",{"type":"map" > > ,"values":"robject"}],"comments":"Attributes"}, > > {"name":"c","type":[ > > "null", > > {"name":"int", "type":"record" > > ,"fields":[{"name":"v","type":{"type":"array" > > ,"items":"int"}}]}, > > {"name":"real","type":"record" > > ,"fields":[{"name":"v","type":{"type":"array" > > ,"items":"double"}}]}, > > {"name":"list","type":"record" > > ,"fields":[{"name":"v","type":{"type":"array" > > ,"items":"robject"}}]} > > ] > > ,"comments": "Content"} > > ] > > } > > > > > > >
