File: jsonwrt.h

package info (click to toggle)
util-linux 2.41.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,868 kB
  • sloc: ansic: 179,124; sh: 22,714; yacc: 1,284; makefile: 525; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (58 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * No copyright is claimed.  This code is in the public domain; do with
 * it what you wish.
 */
#ifndef UTIL_LINUX_JSONWRT_H
#define UTIL_LINUX_JSONWRT_H

enum {
	UL_JSON_OBJECT,
	UL_JSON_ARRAY,
	UL_JSON_VALUE
};

struct ul_jsonwrt {
	FILE *out;
	int indent;

	unsigned int after_close :1;
};

void ul_jsonwrt_init(struct ul_jsonwrt *fmt, FILE *out, int indent);
int ul_jsonwrt_is_ready(struct ul_jsonwrt *fmt);
void ul_jsonwrt_indent(struct ul_jsonwrt *fmt);
void ul_jsonwrt_open(struct ul_jsonwrt *fmt, const char *name, int type);
void ul_jsonwrt_close(struct ul_jsonwrt *fmt, int type);
void ul_jsonwrt_empty(struct ul_jsonwrt *fmt, const char *name, int type);
void ul_jsonwrt_flush(struct ul_jsonwrt *fmt);

#define ul_jsonwrt_root_open(_f)	ul_jsonwrt_open(_f, NULL, UL_JSON_OBJECT)
#define ul_jsonwrt_root_close(_f)	ul_jsonwrt_close(_f, UL_JSON_OBJECT)

#define ul_jsonwrt_array_open(_f, _n)	ul_jsonwrt_open(_f, _n, UL_JSON_ARRAY)
#define ul_jsonwrt_array_close(_f)	ul_jsonwrt_close(_f, UL_JSON_ARRAY)
#define ul_jsonwrt_array_empty(_f, _n)	ul_jsonwrt_empty(_f, _n, UL_JSON_ARRAY)

#define ul_jsonwrt_object_open(_f, _n)	ul_jsonwrt_open(_f, _n, UL_JSON_OBJECT)
#define ul_jsonwrt_object_close(_f)	ul_jsonwrt_close(_f, UL_JSON_OBJECT)
#define ul_jsonwrt_object_empty(_f, _n)	ul_jsonwrt_empty(_f, _n, UL_JSON_OBJECT)

#define ul_jsonwrt_value_open(_f, _n)	ul_jsonwrt_open(_f, _n, UL_JSON_VALUE)
#define ul_jsonwrt_value_close(_f)	ul_jsonwrt_close(_f, UL_JSON_VALUE)

void ul_jsonwrt_value_raw(struct ul_jsonwrt *fmt,
			const char *name, const char *data);
void ul_jsonwrt_value_s(struct ul_jsonwrt *fmt,
			const char *name, const char *data);
void ul_jsonwrt_value_s_sized(struct ul_jsonwrt *fmt,
			      const char *name, const char *data, size_t size);
void ul_jsonwrt_value_u64(struct ul_jsonwrt *fmt,
			const char *name, uint64_t data);
void ul_jsonwrt_value_double(struct ul_jsonwrt *fmt,
			const char *name, long double data);
void ul_jsonwrt_value_boolean(struct ul_jsonwrt *fmt,
			const char *name, int data);

#define ul_jsonwrt_value_null(_f, _n)	ul_jsonwrt_empty(_f, _n, UL_JSON_VALUE)

#endif /* UTIL_LINUX_JSONWRT_H */