On 09/27/2016 08:13 AM, Daniel P. Berrange wrote: > The qdict_flatten() method will take a dict whose elements are > further nested dicts/lists and flatten them by concatenating > keys. > > The qdict_crumple() method aims to do the reverse, taking a flat > qdict, and turning it into a set of nested dicts/lists. It will > apply nesting based on the key name, with a '.' indicating a > new level in the hierarchy. If the keys in the nested structure > are all numeric, it will create a list, otherwise it will create > a dict. > > If the keys are a mixture of numeric and non-numeric, or the > numeric keys are not in strictly ascending order, an error will > be reported. >
> > The intent of this function is that it allows a set of QemuOpts > to be turned into a nested data structure that mirrors the nesting > used when the same object is defined over QMP. > > Reviewed-by: Kevin Wolf <kw...@redhat.com> > Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> > Signed-off-by: Daniel P. Berrange <berra...@redhat.com> > --- > + > +/** > + * qdict_split_flat_key: > + * @key: the key string to split > + * @prefix: non-NULL pointer to hold extracted prefix > + * @suffix: non-NULL pointer to remaining suffix > + * > + * Given a flattened key such as 'foo.0.bar', split it into two parts > + * at the first '.' separator. Allows double dot ('..') to escape the > + * normal separator. > + * > + * eg s/eg/e.g./ or just spell it as 'for example' > +static int qdict_is_list(QDict *maybe_list, Error **errp) > + > + /* NB this isn't a perfect check - eg it won't catch Another such use. > + * a list containing '1', '+1', '01', '3', but that > + * does not matter - we've still proved that the > + * input is a list. It is up the caller to do a > + * stricter check if desired */ > + if (len != (max + 1)) { > + error_setg(errp, "List indexes are not contiguous, " s/indexes/indices/ ? (my spellchecker likes both, but indexes is a sign that modern English speakers are getting lazy and drifting away from Latin) > +/** > + * qdict_crumple: > + * @src: the original flat dictionary (only scalar values) to crumple > + * @recursive: true to recursively crumple nested dictionaries > + * For example, an input of: > + * > + * { 'foo.0.bar': 'one', 'foo.0.wizz': '1', > + * 'foo.1.bar': 'two', 'foo.1.wizz': '2' } > + * > + * will result in any output of: s/any/an/ > + * > + * { > + * 'foo': [ > + * { 'bar': 'one', 'wizz': '1' }, > + * { 'bar': 'two', 'wizz': '2' } > + * ], > + * } > + * > + * The following scenarios in the input dict will result in an > + * error being returned: > + * > + * - Any values in @src are non-scalar types > + * - If keys in @src imply that a particular level is both a > + * list and a dict. eg, "foo.0.bar" and "foo.eek.bar". > + * - If keys in @src imply that a particular level is a list, > + * but the indexes are non-contigous. eg "foo.0.bar" and s/contigous/contiguous/ and another pesky 'eg' Modulo typo fixes and potential grammar changes, Reviewed-by: Eric Blake <ebl...@redhat.com> -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature