aboutsummaryrefslogtreecommitdiff
path: root/qobject
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-03-05 18:29:50 +0100
committerEric Blake <eblake@redhat.com>2018-03-19 10:00:14 -0500
commit3cf42b8b3af1bd61e736a9ca0f94806c7931ae56 (patch)
tree15cff8ff932d07da1143a70d5c7d04b2157f157a /qobject
parent3d96ea44d4dde442094b7d9e5b71ef61b4c4ae39 (diff)
qlit: add qobject_from_qlit()
Instantiate a QObject* from a literal QLitObject. LitObject only supports int64_t for now. uint64_t and double aren't implemented. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180305172951.2150-4-marcandre.lureau@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qobject')
-rw-r--r--qobject/qlit.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/qobject/qlit.c b/qobject/qlit.c
index 948e0b860c..d0e1b72fd0 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -21,6 +21,7 @@
#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qnull.h"
static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
{
@@ -86,3 +87,39 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
return false;
}
+
+QObject *qobject_from_qlit(const QLitObject *qlit)
+{
+ switch (qlit->type) {
+ case QTYPE_QNULL:
+ return QOBJECT(qnull());
+ case QTYPE_QNUM:
+ return QOBJECT(qnum_from_int(qlit->value.qnum));
+ case QTYPE_QSTRING:
+ return QOBJECT(qstring_from_str(qlit->value.qstr));
+ case QTYPE_QDICT: {
+ QDict *qdict = qdict_new();
+ QLitDictEntry *e;
+
+ for (e = qlit->value.qdict; e->key; e++) {
+ qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value));
+ }
+ return QOBJECT(qdict);
+ }
+ case QTYPE_QLIST: {
+ QList *qlist = qlist_new();
+ QLitObject *e;
+
+ for (e = qlit->value.qlist; e->type != QTYPE_NONE; e++) {
+ qlist_append_obj(qlist, qobject_from_qlit(e));
+ }
+ return QOBJECT(qlist);
+ }
+ case QTYPE_QBOOL:
+ return QOBJECT(qbool_from_bool(qlit->value.qbool));
+ default:
+ assert(0);
+ }
+
+ return NULL;
+}