Add the 'I' format for both pack and unpack

This commit is contained in:
Petri Lehtinen 2011-01-25 21:41:35 +02:00
parent a1c185a376
commit 908c62f327

View File

@ -166,9 +166,12 @@ static json_t *pack(scanner_t *s, va_list *ap)
case 'b': /* boolean */
return va_arg(*ap, int) ? json_true() : json_false();
case 'i': /* integer */
case 'i': /* integer from int */
return json_integer(va_arg(*ap, int));
case 'I': /* integer from json_int_t */
return json_integer(va_arg(*ap, json_int_t));
case 'f': /* real */
return json_real(va_arg(*ap, double));
@ -368,6 +371,17 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap)
return 0;
case 'I':
if(!json_is_integer(root)) {
set_error(s, "Expected integer, got %s", type_name(root));
return -1;
}
if(!(s->flags & JSON_VALIDATE_ONLY))
*va_arg(*ap, json_int_t*) = json_integer_value(root);
return 0;
case 'b':
if(!json_is_boolean(root)) {
set_error(s, "Expected true or false, got %s", type_name(root));