On 05/09/2018 11:55 AM, Max Reitz wrote:
Signed-off-by: Max Reitz <mre...@redhat.com>
---
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 <ebl...@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org