projects
/
jansson.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a1c185a
)
Add the 'I' format for both pack and unpack
author
Petri Lehtinen
<petri@digip.org>
Tue, 25 Jan 2011 19:41:35 +0000
(21:41 +0200)
committer
Petri Lehtinen
<petri@digip.org>
Tue, 25 Jan 2011 19:41:35 +0000
(21:41 +0200)
src/pack_unpack.c
patch
|
blob
|
history
diff --git
a/src/pack_unpack.c
b/src/pack_unpack.c
index
8d8aa33
..
e785357
100644
(file)
--- a/
src/pack_unpack.c
+++ b/
src/pack_unpack.c
@@
-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 '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));
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));
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;
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));
case 'b':
if(!json_is_boolean(root)) {
set_error(s, "Expected true or false, got %s", type_name(root));