From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8WGa-0002GR-6n for qemu-devel@nongnu.org; Tue, 06 Jan 2015 10:42:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8WGW-0002WN-4O for qemu-devel@nongnu.org; Tue, 06 Jan 2015 10:41:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8WGV-0002WH-Ls for qemu-devel@nongnu.org; Tue, 06 Jan 2015 10:41:52 -0500 Message-ID: <54AC023D.80501@redhat.com> Date: Tue, 06 Jan 2015 08:41:49 -0700 From: Eric Blake MIME-Version: 1.0 References: <1419604968-87437-1-git-send-email-agraf@suse.de> <1419604968-87437-2-git-send-email-agraf@suse.de> In-Reply-To: <1419604968-87437-2-git-send-email-agraf@suse.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="e7n7jcrjc8dVTXhEvVUGFLuftqdjWJIe2" Subject: Re: [Qemu-devel] [PATCH v3 1/5] QJSON: Add JSON writer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf , qemu-devel@nongnu.org Cc: amit.shah@redhat.com, pbonzini@redhat.com, afaerber@suse.de, quintela@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --e7n7jcrjc8dVTXhEvVUGFLuftqdjWJIe2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/26/2014 07:42 AM, Alexander Graf wrote: > To support programmatic JSON assembly while keeping the code that gener= ates it > readable, this patch introduces a simple JSON writer. It emits JSON ser= ially > into a buffer in memory. >=20 > The nice thing about this writer is its simplicity and low memory overh= ead. > Unlike the QMP JSON writer, this one does not need to spawn QObjects fo= r every > element it wants to represent. >=20 > This is a prerequisite for the migration stream format description gene= rator. >=20 > Signed-off-by: Alexander Graf > --- > Makefile.objs | 1 + > include/qjson.h | 28 +++++++++++++++++ > qjson.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 3 files changed, 126 insertions(+) > create mode 100644 include/qjson.h > create mode 100644 qjson.c > +struct QJSON { > + QString *str; > + bool omit_comma; > + unsigned long self_size_offset; Would size_t be smarter for this field? > +} > + > +const char *qjson_get_str(QJSON *json) > +{ > + return qstring_get_str(json->str); > +} > + > +QJSON *qjson_new(void) > +{ > + QJSON *json =3D g_new(QJSON, 1); > + json->str =3D qstring_from_str("{ "); > + json->omit_comma =3D true; > + return json; If I'm not mistaken, this creates an open-ended object, as in "{ ...". Should qjson_get_str add the closing }? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --e7n7jcrjc8dVTXhEvVUGFLuftqdjWJIe2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJUrAI9AAoJEKeha0olJ0NqFMoH/0jZldpYrEBoQU59s+6d3+1S ptWzAdrBsUQaJVd1e+tFbJ+KuYjrl1z8nFxj6vZYwIhj7vkraJts0p9jUV0UYZ/t K0t17ToqaIyhvyTw/cz8iyxGjSdMI1Z1F5UCm7Ch0crFdCqol1cbEoi3jSWlNP5l Zomadj5LnQ/YeN5f/v8FnhKFwVnAgBtEeUnKACclOdNUdTUcxBxpTkLaQPzZ78e1 HS+I5MbobDXheVUuxDn8hQc8V5MFyXHrUNLANYNDmJm/yHGFMHjzcDJcOpJGZQ01 Yhixw4HJ0PFps6mgkeLgPVQh6FEimGsyElitGjZC3NVHC0cNNcMIAHcRvoAuOM4= =Cn6u -----END PGP SIGNATURE----- --e7n7jcrjc8dVTXhEvVUGFLuftqdjWJIe2--