qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 02/13] docs/qapi: Document optional discriminato


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 02/13] docs/qapi: Document optional discriminators
Date: Thu, 10 May 2018 08:14:13 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 05/09/2018 11:55 AM, Max Reitz wrote:
Signed-off-by: Max Reitz <address@hidden>
---
  docs/devel/qapi-code-gen.txt | 21 +++++++++++++++++++--
  1 file changed, 19 insertions(+), 2 deletions(-)


I might have squashed this in with patch 1, but I can live with it separate.

@@ -502,6 +502,23 @@ the enum).  In the resulting generated C data types, a 
flat union is
  represented as a struct with the base members included directly, and
  then a union of structures for each branch of the struct.
+If the discriminator points to an optional member of the base struct,
+its default value must be specified as a 'default-variant'.  In the
+following example, the above BlockDriver struct is changed so it
+defaults to the 'file' driver if that field is omitted on the wire:
+
+ { 'union': 'BlockdevOptions',
+   'base': { '*driver': 'BlockdevDriver', '*read-only': 'bool' },
+   'discriminator': 'driver',
+   'default-variant': 'file',
+   'data': { 'file': 'BlockdevOptionsFile',
+             'qcow2': 'BlockdevOptionsQcow2' } }
+
+Now the 'file' JSON object can be abbreviated to:
+
+ { "read-only": "true",
+   "filename": "/some/place/my-image" }
+

Reviewed-by: Eric Blake <address@hidden>

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]