Received: from eggs.gnu.org ([2001:4830:134:3::10]:42260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axFMf-0003C3-A6 for qemu-devel@nongnu.org; Mon, 02 May 2016 11:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axFLB-0000QJ-KS for qemu-devel@nongnu.org; Mon, 02 May 2016 11:02:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44860) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axFLB-0000Nj-A0 for qemu-devel@nongnu.org; Mon, 02 May 2016 11:00:53 -0400 From: Markus Armbruster References: <1461903820-3092-1-git-send-email-eblake@redhat.com> <1461903820-3092-8-git-send-email-eblake@redhat.com> Date: Mon, 02 May 2016 17:00:39 +0200 In-Reply-To: <1461903820-3092-8-git-send-email-eblake@redhat.com> (Eric Blake's message of "Thu, 28 Apr 2016 22:23:28 -0600") Message-ID: <87wpncijxk.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 07/18] qapi: Add json output visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, famz@redhat.com, Michael Roth Eric Blake writes: > 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. > > Signed-off-by: Eric Blake > > --- > v3: retitle, rebase to master, minor cleanups > v2: rebase to qapi subset E v8; add test of error outputting > infinity; use unsigned depth > --- > include/qapi/visitor.h | 20 +- > include/qapi/json-output-visitor.h | 29 +++ > qapi/json-output-visitor.c | 202 ++++++++++++++++++ > tests/test-json-output-visitor.c | 418 +++++++++++++++++++++++++++++++++++++ > qapi/Makefile.objs | 2 +- > tests/.gitignore | 1 + > tests/Makefile | 4 + > 7 files changed, 665 insertions(+), 11 deletions(-) > create mode 100644 include/qapi/json-output-visitor.h > create mode 100644 qapi/json-output-visitor.c > create mode 100644 tests/test-json-output-visitor.c > > diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h > index a430c19..e8a4403 100644 > --- a/include/qapi/visitor.h > +++ b/include/qapi/visitor.h > @@ -26,16 +26,16 @@ > * > * There are three kinds of visitor classes: input visitors (QMP, > * string, and QemuOpts) parse an external representation and build > - * the corresponding QAPI graph, output visitors (QMP and string) take > - * a completed QAPI graph and generate an external representation, and > - * the dealloc visitor can take a QAPI graph (possibly partially > - * constructed) and recursively free its resources. While the dealloc > - * and QMP input/output visitors are general, the string and QemuOpts > - * visitors have some implementation limitations; see the > - * documentation for each visitor for more details on what it > - * supports. Also, see visitor-impl.h for the callback contracts > - * implemented by each visitor, and docs/qapi-code-gen.txt for more > - * about the QAPI code generator. > + * the corresponding QAPI graph, output visitors (QMP, string, and > + * JSON) take a completed QAPI graph and generate an external > + * representation, and the dealloc visitor can take a QAPI graph > + * (possibly partially constructed) and recursively free its > + * resources. While the dealloc and QMP input/output visitors are and the JSON output visitor? > + * general, the string and QemuOpts visitors have some implementation > + * limitations; see the documentation for each visitor for more > + * details on what it supports. Also, see visitor-impl.h for the > + * callback contracts implemented by each visitor, and > + * docs/qapi-code-gen.txt for more about the QAPI code generator. > * > * All QAPI types have a corresponding function with a signature > * roughly compatible with this: [...]