Jason Wang <jasow...@redhat.com> writes:

[...]
> One more stupid question, instead of generating the string via hard
> codes, is there any method (dict?) to iterate all the key/values 
> automatically?

QAPI visitors.

The lazy way: use the QObject output visitor to convert the QAPI type
(here: NetdevInfo) to QObject, then qobject_to_json() to convert to
JSON text.

If you don't want JSON, replace qobject_to_json().  Perhaps you can
create something that's generally useful for HMP, not just "info
network".  I'd pick keyval_parse() syntax.

The detour through QObject creates and destroys a rather fat temporary
data structure.  Tolerable when the amount of data is small.  An output
visitor that directly creates the string is more efficient.  Takes a bit
more code, though.  I intend to post one for JSON, to reduce QMP's
malloc gluttony.


Reply via email to