提交 68ecbca5 编写于 作者: P Peter Krempa

util: json: Allow converting a virTristate(Bool|Switch) into JSON

Add a new modifier letter for virJSONValueObjectAddVArgs which will add
a boolean value with our tristate semantics. The value is omitted when
the _ABSENT value is used.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 350e238f
......@@ -142,6 +142,8 @@ virJSONValueGetType(const virJSONValue *value)
*
* b: boolean value
* B: boolean value, omitted if false
* T: boolean value specified by a virTristate(Bool|Switch) value, omitted on
* the _ABSENT value
*
* d: double precision floating point number
* n: json null value
......@@ -265,6 +267,7 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
rc = virJSONValueObjectAppendNumberDouble(obj, key, val);
} break;
case 'T':
case 'B':
case 'b': {
int val = va_arg(args, int);
......@@ -272,6 +275,16 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj,
if (!val && type == 'B')
continue;
if (type == 'T') {
if (val == VIR_TRISTATE_BOOL_ABSENT)
continue;
if (val == VIR_TRISTATE_BOOL_NO)
val = 0;
else
val = 1;
}
rc = virJSONValueObjectAppendBoolean(obj, key, val);
} break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册