projects
/
jansson.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
cd97575
)
new typedef json_dump_callback_t, function json_dump_callback
author
JKL
<jkl@thirddefense.com>
Fri, 24 Jun 2011 17:00:53 +0000
(10:00 -0700)
committer
Petri Lehtinen
<petri@digip.org>
Thu, 30 Jun 2011 18:47:12 +0000
(21:47 +0300)
src/dump.c
patch
|
blob
|
history
src/jansson.h
patch
|
blob
|
history
diff --git
a/src/dump.c
b/src/dump.c
index
f32f667
..
344670a
100644
(file)
--- a/
src/dump.c
+++ b/
src/dump.c
@@
-19,8
+19,6
@@
#define MAX_INTEGER_STR_LENGTH 100
#define MAX_REAL_STR_LENGTH 100
#define MAX_INTEGER_STR_LENGTH 100
#define MAX_REAL_STR_LENGTH 100
-typedef int (*dump_func)(const char *buffer, int size, void *data);
-
struct string
{
char *buffer;
struct string
{
char *buffer;
@@
-28,12
+26,12
@@
struct string
int size;
};
int size;
};
-static int dump_to_strbuffer(const char *buffer,
in
t size, void *data)
+static int dump_to_strbuffer(const char *buffer,
size_
t size, void *data)
{
return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
}
{
return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
}
-static int dump_to_file(const char *buffer,
in
t size, void *data)
+static int dump_to_file(const char *buffer,
size_
t size, void *data)
{
FILE *dest = (FILE *)data;
if(fwrite(buffer, size, 1, dest) != 1)
{
FILE *dest = (FILE *)data;
if(fwrite(buffer, size, 1, dest) != 1)
@@
-44,7
+42,7
@@
static int dump_to_file(const char *buffer, int size, void *data)
/* 32 spaces (the maximum indentation size) */
static char whitespace[] = " ";
/* 32 spaces (the maximum indentation size) */
static char whitespace[] = " ";
-static int dump_indent(size_t flags, int depth, int space,
dump_func
dump, void *data)
+static int dump_indent(size_t flags, int depth, int space,
json_dump_callback_t
dump, void *data)
{
if(JSON_INDENT(flags) > 0)
{
{
if(JSON_INDENT(flags) > 0)
{
@@
-66,7
+64,7
@@
static int dump_indent(size_t flags, int depth, int space, dump_func dump, void
return 0;
}
return 0;
}
-static int dump_string(const char *str, int ascii,
dump_func
dump, void *data)
+static int dump_string(const char *str, int ascii,
json_dump_callback_t
dump, void *data)
{
const char *pos, *end;
int32_t codepoint;
{
const char *pos, *end;
int32_t codepoint;
@@
-166,7
+164,7
@@
static int object_key_compare_serials(const void *key1, const void *key2)
}
static int do_dump(const json_t *json, size_t flags, int depth,
}
static int do_dump(const json_t *json, size_t flags, int depth,
-
dump_func
dump, void *data)
+
json_dump_callback_t
dump, void *data)
{
int ascii = flags & JSON_ENSURE_ASCII ? 1 : 0;
{
int ascii = flags & JSON_ENSURE_ASCII ? 1 : 0;
@@
-463,3
+461,13
@@
int json_dump_file(const json_t *json, const char *path, size_t flags)
fclose(output);
return result;
}
fclose(output);
return result;
}
+
+int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags)
+{
+ if(!(flags & JSON_ENCODE_ANY)) {
+ if(!json_is_array(json) && !json_is_object(json))
+ return -1;
+ }
+
+ return do_dump(json, flags, 0, callback, data);
+}
diff --git
a/src/jansson.h
b/src/jansson.h
index
3abb4cf
..
8275e4f
100644
(file)
--- a/
src/jansson.h
+++ b/
src/jansson.h
@@
-234,10
+234,12
@@
json_t *json_load_file(const char *path, size_t flags, json_error_t *error);
#define JSON_PRESERVE_ORDER 0x100
#define JSON_ENCODE_ANY 0x200
#define JSON_PRESERVE_ORDER 0x100
#define JSON_ENCODE_ANY 0x200
+typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
+
char *json_dumps(const json_t *json, size_t flags);
int json_dumpf(const json_t *json, FILE *output, size_t flags);
int json_dump_file(const json_t *json, const char *path, size_t flags);
char *json_dumps(const json_t *json, size_t flags);
int json_dumpf(const json_t *json, FILE *output, size_t flags);
int json_dump_file(const json_t *json, const char *path, size_t flags);
-
+int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags);
/* custom memory allocation */
/* custom memory allocation */