qobject: Factor JSON writer out of qobject_to_json()
We have two JSON writers written in C: qobject/qjson.c provides
qobject_to_json(), and migration/qjson.c provides a more low level
imperative interface. They don't share code. The latter tacitly
limits numbers to int64_t, and strings contents to characters that
don't need escaping.
Factor out qobject_to_json()'s JSON writer as qobject/json-writer.c.
Straightforward, except for numbers: since the writer is to be
independent of QObject, it can't use qnum_to_string(). Open-code it
instead. This is actually an improvement of sorts, because it
liberates qnum_to_string() from JSON's needs: its JSON-related FIXMEs
move to the JSON writer, where they belong.
The next commit will replace migration/qjson.c.
Signed-off-by:
Markus Armbruster <armbru@redhat.com>
Message-Id: <20201211171152.146877-16-armbru@redhat.com>
Showing
- include/qapi/qmp/json-writer.h 37 additions, 0 deletionsinclude/qapi/qmp/json-writer.h
- qobject/json-writer.c 247 additions, 0 deletionsqobject/json-writer.c
- qobject/meson.build 3 additions, 2 deletionsqobject/meson.build
- qobject/qjson.c 30 additions, 93 deletionsqobject/qjson.c
- qobject/qnum.c 0 additions, 5 deletionsqobject/qnum.c
include/qapi/qmp/json-writer.h
0 → 100644
qobject/json-writer.c
0 → 100644
Please register or sign in to comment