[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 1/5] QJSON: Add JSON writer
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v3 1/5] QJSON: Add JSON writer |
Date: |
Tue, 06 Jan 2015 08:41:49 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 12/26/2014 07:42 AM, Alexander Graf wrote:
> To support programmatic JSON assembly while keeping the code that generates it
> readable, this patch introduces a simple JSON writer. It emits JSON serially
> into a buffer in memory.
>
> The nice thing about this writer is its simplicity and low memory overhead.
> Unlike the QMP JSON writer, this one does not need to spawn QObjects for every
> element it wants to represent.
>
> This is a prerequisite for the migration stream format description generator.
>
> Signed-off-by: Alexander Graf <address@hidden>
> ---
> 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 = g_new(QJSON, 1);
> + json->str = qstring_from_str("{ ");
> + json->omit_comma = true;
> + return json;
If I'm not mistaken, this creates an open-ended object, as in "{ ...".
Should qjson_get_str add the closing }?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH v3 1/5] QJSON: Add JSON writer,
Eric Blake <=