From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56528 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ODCzd-00022m-W0 for qemu-devel@nongnu.org; Sat, 15 May 2010 04:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ODCza-00089p-1Z for qemu-devel@nongnu.org; Sat, 15 May 2010 04:45:07 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:55527) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ODCzZ-00089i-LL for qemu-devel@nongnu.org; Sat, 15 May 2010 04:45:06 -0400 Message-ID: <4BEE5F0F.2060600@web.de> Date: Sat, 15 May 2010 10:45:03 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <6e14cbfe3764b46d9bd6d2db61d41fd9c85dd54e.1273843151.git.jan.kiszka@siemens.com> <4BED9358.1000106@codemonkey.ws> In-Reply-To: <4BED9358.1000106@codemonkey.ws> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigE59778F6B3361BEDEACB0CA4" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH 3/8] Add QBuffer List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Anthony Liguori , Juan Quintela , qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino , Avi Kivity This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigE59778F6B3361BEDEACB0CA4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Anthony Liguori wrote: > On 05/14/2010 08:20 AM, Jan Kiszka wrote: >> diff --git a/qjson.c b/qjson.c >> index 483c667..4d1c21a 100644 >> --- a/qjson.c >> +++ b/qjson.c >> @@ -19,7 +19,9 @@ >> #include "qlist.h" >> #include "qbool.h" >> #include "qfloat.h" >> +#include "qbuffer.h" >> #include "qdict.h" >> +#include "base64.h" >> >> typedef struct JSONParsingState >> { >> @@ -235,6 +237,20 @@ static void to_json(const QObject *obj, QString >> *str) >> } >> break; >> } >> + case QTYPE_QBUFFER: { >> + QBuffer *val =3D qobject_to_qbuffer(obj); >> + size_t data_size =3D qbuffer_get_size(val); >> + size_t str_len =3D ((data_size + 2) / 3) * 4; >> + char *buffer =3D qemu_malloc(str_len + 3); >> + >> + buffer[0] =3D '"'; >> + base64_encode(qbuffer_get_data(val), data_size, buffer + 1); >> + buffer[str_len + 1] =3D '"'; >> + buffer[str_len + 2] =3D 0; >> + qstring_append(str, buffer); >> + qemu_free(buffer); >> + break; >> + } >> =20 >=20 > Instead of encoding just as a string, it would be a good idea to encode= > it as something like: >=20 > {'__class__': 'base64', 'data': ...} >=20 > We've discussed using hidden properties to describe special things like= > abstract classes and since we already have this namespace reserved, I > think it's a good time to use it. >=20 > The advantage is that in a dynamic language like Python, the parser can= > convert base64 to binary strings automatically without having to > understand the QMP protocol. Indeed, was amazingly simple to add and works nicely with qmp-shell as demonstrator. Will repost, also to fix a few remaining glitches I came across in the meantime. Jan --------------enigE59778F6B3361BEDEACB0CA4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkvuXw8ACgkQitSsb3rl5xT0zQCfaAj02O1f4MjB1n/F8E8i6m9R dRcAoM2ZueoctsoTwy6TlKdhJobLKztJ =1aLI -----END PGP SIGNATURE----- --------------enigE59778F6B3361BEDEACB0CA4--