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 <ag...@suse.de> > --- > 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