[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 07/11] qapi: add json output visitor
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 07/11] qapi: add json output visitor |
Date: |
Thu, 10 Dec 2015 17:24:36 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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
- [Qemu-devel] [PATCH 02/11] qapi: Improve use of qmp/types.h, (continued)
- [Qemu-devel] [PATCH 02/11] qapi: Improve use of qmp/types.h, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 04/11] qapi: Factor out JSON number formatting, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 03/11] qapi: Factor out JSON string escaping, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 05/11] qapi: Use qstring_append_chr() where appropriate, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 08/11] qjson: Simplify by using json-output-visitor, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 09/11] qapi: Add qobject_to_json_pretty_prefix(), Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 10/11] qapi: Support pretty printing in JSON output visitor, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 01/11] qapi: Rename qjson.h to qobject-json.h, Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 06/11] qapi: Add qstring_append_format(), Eric Blake, 2015/12/10
- [Qemu-devel] [PATCH 07/11] qapi: add json output visitor, Eric Blake, 2015/12/10
- Re: [Qemu-devel] [PATCH 07/11] qapi: add json output visitor,
Eric Blake <=
- [Qemu-devel] [PATCH 11/11] RFC: qemu-img: Use new JSON output formatter, Eric Blake, 2015/12/10