On 12/10/2015 04:53 PM, Eric Blake wrote: > We have several places that want to go from qapi to JSON; right now, > they have to create an intermediate QObject to do the work. That > also has the drawback that the JSON formatting of a QDict will > rearrange keys (according to a deterministic, but unpredictable, > hash), when humans have an easier time if dicts are produced in > the same order as the qapi type. > > For these reasons, it is time to add a new JSON output visitor. > This patch just adds the basic visitor and tests that it works; > later patches will add pretty-printing, and convert clients to > use the visitor. > > Design choices: Unlike the QMP output visitor, the JSON visitor > refuses to visit a required string with a NULL value (abort), as > well as a non-finite number (raises an error message). Reusing > QString to grow the contents means that we easily share code with > both qobject-json.c and qjson.c; although it might be nice to > enhance things to take an optional output callback function so > that the output can truly be streamed instead of collected in > memory. >
> +static void json_output_type_number(Visitor *v, double *obj, const char > *name, > + Error **errp) > +{ > + JsonOutputVisitor *jov = to_jov(v); > + json_output_name(jov, name); > + qstring_append_json_number(jov->str, *obj, errp); > +} Hmm. The generated qapi callers always pass a non-NULL local errp, and fail the overall iteration even if the upper-level caller passed NULL. My intent here was to allow the choice between diagnosing NaN, or ignoring the problem and producing output anyways; but for that to work, I may need to add a configuration parameter 'bool strict' at the creation of the visitor, that determines whether I pass errp or NULL on to qstring_append_json_number() here. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature