qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Michael Roth <mdroth@linux.vnet.ibm.com>,
	Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH v3 2/8] docs/qapi: Document optional discriminators
Date: Wed,  6 Feb 2019 20:55:45 +0100	[thread overview]
Message-ID: <20190206195551.28893-3-mreitz@redhat.com> (raw)
In-Reply-To: <20190206195551.28893-1-mreitz@redhat.com>

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 docs/devel/qapi-code-gen.txt | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 87183d3a09..32c576f30b 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -472,8 +472,8 @@ All branches of the union must be complex types, and the top-level
 members of the union dictionary on the wire will be combination of
 members from both the base type and the appropriate branch type (when
 merging two dictionaries, there must be no keys in common).  The
-'discriminator' member must be the name of a non-optional enum-typed
-member of the base struct.
+'discriminator' member must be the name of an enum-typed member of the
+base struct.
 
 The following example enhances the above simple union example by
 adding an optional common member 'read-only', renaming the
@@ -504,6 +504,23 @@ 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" }
+
 A simple union can always be re-written as a flat union where the base
 class has a single member named 'type', and where each branch of the
 union has a struct with a single member named 'data'.  That is,
-- 
2.20.1

  parent reply	other threads:[~2019-02-06 19:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06 19:55 [Qemu-devel] [PATCH v3 0/8] block: Try to create well-typed json:{} filenames Max Reitz
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 1/8] qapi: Add default-variant for flat unions Max Reitz
2019-02-06 20:13   ` Eric Blake
2019-02-07  6:56   ` Markus Armbruster
2019-02-07 14:01     ` Eric Blake
2019-02-07 14:46       ` Eric Blake
2019-02-08 18:21     ` Max Reitz
2019-06-05 19:00       ` Eric Blake
2019-02-06 19:55 ` Max Reitz [this message]
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 3/8] tests: Add QAPI optional discriminator tests Max Reitz
2019-02-06 20:20   ` Eric Blake
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 4/8] qapi: Formalize qcow2 encryption probing Max Reitz
2019-02-06 20:23   ` Eric Blake
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 5/8] qapi: Formalize qcow " Max Reitz
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 6/8] block: Try to create well typed json:{} filenames Max Reitz
2019-02-06 20:43   ` Eric Blake
2019-02-06 21:06     ` Eric Blake
2019-02-08 18:11     ` Max Reitz
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 7/8] iotests: Test internal option typing Max Reitz
2019-02-06 21:28   ` Eric Blake
2019-02-06 19:55 ` [Qemu-devel] [PATCH v3 8/8] iotests: qcow2's encrypt.format is now optional Max Reitz
2019-02-06 21:31   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190206195551.28893-3-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).