Message ID | 20130416101322.GA9337@t430s.nay.redhat.com |
---|---|
State | New |
Headers | show |
On 04/16/2013 04:13 AM, Amos Kong wrote: > Eric said String list contains additional JSON structure. > At least, it works. Using the fat 'String' wrapper works, but requires more effort to decode. > > ===================== using StringList > '*unicast': ['String'], > '*multicast': ['String'] > > { > "return": [ > { > "name": "virtio-net-pci.0", > "multicast": [ > { > "str": "01:80:c2:00:00:21" > }, > { > "str": "00:00:00:00:00:00" > } > ] Libvirt can live with this, even though it is more work, if you can't figure out how to make 'str' work. I don't know enough about the JSON generator to quickly dive in and figure out why you can't make an array of native types, though. > }, > .... > ] > } > ======================== using strList > '*unicast': ['str'], > '*multicast': ['str'] > > Eric, is it expected format? > > { > "return": [ > { > "name": "virtio-net-pci.0", > "multicast": [ > "str": "01:80:c2:00:00:21", > "str": "00:00:00:00:00:00" > ] No. This is not valid JSON. ':' is only allowed inside {}. The point of an array is to either have an array of objects (as in [ {'name':value}, {'name':value} ]) or an array of native types (as in [ value, value ]). The ideal solution is for the output QMP to look like: "multicast": [ "01:80:c2:00:00:21", "00:00:00:00:00:00" ] which seems like it should work as '*multicast':['str'], if you can figure out how to make the generator play along.
===================== using StringList '*unicast': ['String'], '*multicast': ['String'] { "return": [ { "name": "virtio-net-pci.0", "multicast": [ { "str": "01:80:c2:00:00:21" }, { "str": "00:00:00:00:00:00" } ] }, .... ] } ======================== using strList '*unicast': ['str'], '*multicast': ['str'] Eric, is it expected format? { "return": [ { "name": "virtio-net-pci.0", "multicast": [ "str": "01:80:c2:00:00:21", "str": "00:00:00:00:00:00" ] }, .... ] } ======================== I changed qapi scripts to define struct, struct list, visit/free functions for 'str'. But it conflicts with existed str functions. I hadn't find a solution. Do we need to defind strList & visit functions in qapi-core files? not generated by scripts. diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 9e19920..5167d85 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -282,6 +282,10 @@ fdecl.write(mcgen(''' exprs = parse_schema(sys.stdin) exprs = filter(lambda expr: not expr.has_key('gen'), exprs) +ret = "\n" +ret += generate_fwd_struct('str', {'str': 'str'}) +fdecl.write(ret) + for expr in exprs: ret = "\n" if expr.has_key('type'): @@ -319,6 +323,15 @@ for expr in exprs: continue fdecl.write(ret) +ret = "\n" +ret += generate_struct('str', "", {'str': 'str'}) + "\n" +ret += generate_type_cleanup_decl('str' + "List") +fdef.write(generate_type_cleanup('str' + "List") + "\n") +ret += generate_type_cleanup_decl('str') +fdef.write(generate_type_cleanup('str') + "\n") + +fdecl.write(ret) + fdecl.write(''' #endif ''') diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index a276540..089dda7 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -354,6 +354,13 @@ for expr in exprs: ret += generate_enum_declaration(expr['enum'], expr['data']) fdecl.write(ret) +ret = generate_visit_struct('str', {'str': 'str'}) +ret += generate_visit_list('str', {'str': 'str'}) +fdef.write(ret) + +ret = generate_declaration('str', {'str': 'str'}) +fdecl.write(ret) + fdecl.write(''' #endif ''')