[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 3/4] hmp: Use QMP query-netdev in hmp_info_network
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v5 3/4] hmp: Use QMP query-netdev in hmp_info_network |
Date: |
Tue, 15 Dec 2020 09:39:57 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Jason Wang <jasowang@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.