ObjectPropertyValue member @type is "child<T>" for a child property of QOM type T, and "link<T>" for a link property of QOM type T. Such encoding of information in strings should be avoided in QMP, because it requires clients to parse the strings in addition to parse JSON. Turn ObjectPropertyValue into a union with discriminator @kind and a variant member @qom-type in branches "child" and "link". This provides the same information unencoded. A later commit will deprecate @type. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- qapi/qom.json | 12 +++++++++--- qom/qom-qmp-cmds.c | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index ca74b652a0d..0b274787b3f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -86,6 +86,8 @@ # # @name: the name of the property. # +# @kind: TODO +# # @type: the type of the property, as described in # `ObjectPropertyInfo`. # @@ -101,11 +103,15 @@ # # Since: 10.1 ## -{ 'struct': 'ObjectPropertyValue', - 'data': { 'name': 'str', +{ 'union': 'ObjectPropertyValue', + 'base': { 'name': 'str', + 'kind': 'ObjectPropertyKind', 'type': 'str', 'qapi-type': { 'type': 'str', 'features': [ 'unstable' ] }, - '*value': 'any' } } + '*value': 'any' }, + 'discriminator': 'kind', + 'data': { 'child': 'ObjectPropertyQomType', + 'link': 'ObjectPropertyQomType' } } ## # @ObjectPropertiesValues: diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 2b491caaf7a..d2945d1efe0 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -97,6 +97,15 @@ static void qom_list_add_property_value(Object *obj, ObjectProperty *prop, QAPI_LIST_PREPEND(*props, item); item->name = g_strdup(prop->name); + if (object_property_is_child(prop)) { + item->kind = OBJECT_PROPERTY_KIND_CHILD; + item->u.child.qom_type = g_strdup(prop->qom_type); + } else if (object_property_is_link(prop)) { + item->kind = OBJECT_PROPERTY_KIND_LINK; + item->u.link.qom_type = g_strdup(prop->qom_type); + } else { + item->kind = OBJECT_PROPERTY_KIND_OTHER; + } item->type = g_strdup(prop->type); if (prop->qapi_type) { assert(prop->qapi_type->masked_name); -- 2.55.0