On 07/11/2013 05:57 AM, Eric Blake wrote: > On 07/09/2013 03:53 AM, Kevin Wolf wrote: >> The new 'base' key in a union definition refers to a struct type, which >> is inlined into the union definition and can represent fields common to >> all kinds. > > Is it worth listing an example of intended use in the commit message? > If I understand correctly, then this qapi-schema.json file: > > { 'type': 'Base', > 'data': { 'main': 'str' } } > { 'type': 'Extra1', > 'data': { 'foo': 'str' } } > { 'type': 'Extra2', > 'data': { 'bar': 'str' } } > { 'union': 'Type', > 'base': 'BaseType', > 'data': { 'variant1': 'Extra1', > 'variant2': 'Extra2' } } > { 'command': 'test', > 'data': { 'arg': 'Type' } } > > would then be used over the wire as: > > { "execute": "test", > "arguments": { "arg": { "type": "variant1", > "data": { "main": "hello", "foo": "world" } } } } > { "execute": "test", > "arguments": { "arg": { "type": "variant2", > "data": { "main": "hi", "bar": "there" } } } }
I just read patch 6/11, and it looks like I'm a bit off; it looks like the usage syntax with a base type is actually: { "execute": "test", "arguments": { "arg": { "type": "variant1", "main": "hello", "data": { "foo": "world" } } } } { "execute": "test", "arguments": { "arg": { "type": "variant2", "main": "hi", "data": { "bar": "there" } } } } That is, a union type is automatically granted two top-level keys "type" and "data", and a base type grants it additional top-level keys; nested keys under "data" are still tied to just the type listed in the union. See why a commit message can make a difference in understanding? :) -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature