Rizin
unix-like reverse engineering framework and cli tools
rz_pj.h
Go to the documentation of this file.
1 #ifndef RZ_PJ_H
2 #define RZ_PJ_H
3 
4 #define RZ_PRINT_JSON_DEPTH_LIMIT 128
5 
6 #include <rz_util/rz_strbuf.h>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 typedef struct pj_t {
14  bool is_first;
15  bool is_key;
17  int level;
18 } PJ;
19 
20 /* lifecycle */
21 RZ_API PJ *pj_new(void);
22 RZ_API void pj_free(PJ *j);
23 RZ_API void pj_reset(PJ *j); // clear the pj contents, but keep the buffer allocated to re-use it
24 RZ_API char *pj_drain(PJ *j);
25 /* encode the pj data as a string */
26 RZ_API const char *pj_string(PJ *pj);
27 // RZ_API void pj_print(PJ *j, PrintfCallback cb);
28 RZ_API void pj_raw(PJ *j, const char *k);
29 
30 /* nesting */
31 // RZ_API PJ *pj_begin(char type, PrintfCallback cb);
32 /* close the current json list or array */
33 RZ_API PJ *pj_end(PJ *j);
34 /* object, array */
35 /* open new json list { */
36 RZ_API PJ *pj_o(PJ *j);
37 /* open new array [ */
38 RZ_API PJ *pj_a(PJ *j);
39 /* keys, values */
40 /* new key with no value "name": */
41 RZ_API PJ *pj_k(PJ *j, const char *k);
42 /* "name":"null" */
43 RZ_API PJ *pj_knull(PJ *j, const char *k);
44 /* unsigned "name":n */
45 RZ_API PJ *pj_kn(PJ *j, const char *k, ut64 n);
46 /* signed "name":n */
47 RZ_API PJ *pj_kN(PJ *j, const char *k, st64 n);
48 /* literal key "name":"key" */
49 RZ_API PJ *pj_ks(PJ *j, const char *k, const char *v);
50 
51 /* begin named array entry: "name": [...] */
52 RZ_API PJ *pj_ka(PJ *j, const char *k);
53 /* begin named json entry: "name": {...} */
54 RZ_API PJ *pj_ko(PJ *j, const char *k);
55 
56 /* named entry for primitive types */
57 RZ_API PJ *pj_ki(PJ *j, const char *k, int d);
58 RZ_API PJ *pj_kd(PJ *j, const char *k, double d);
59 RZ_API PJ *pj_kf(PJ *j, const char *k, float d);
60 RZ_API PJ *pj_kb(PJ *j, const char *k, bool v);
61 
62 /* named "null" */
63 RZ_API PJ *pj_null(PJ *j);
64 
65 /* array with first v_len bytes of v */
66 RZ_API PJ *pj_r(PJ *j, const ut8 *v, size_t v_len);
67 
68 /* named entry with pj_r */
69 RZ_API PJ *pj_kr(PJ *j, const char *k, const ut8 *v, size_t v_len);
70 
71 /* string, escaped for json */
72 RZ_API PJ *pj_s(PJ *j, const char *k);
73 /* string, escaped for json without quotes */
74 RZ_API PJ *pj_S(PJ *j, const char *k);
75 /* string, raw */
76 RZ_API PJ *pj_j(PJ *j, const char *k);
77 
78 /* formatted primitive types */
79 RZ_API PJ *pj_n(PJ *j, ut64 n);
80 RZ_API PJ *pj_N(PJ *j, st64 n);
81 RZ_API PJ *pj_i(PJ *j, int d);
82 RZ_API PJ *pj_d(PJ *j, double d);
83 RZ_API PJ *pj_f(PJ *j, float d);
84 RZ_API PJ *pj_b(PJ *j, bool v);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
#define RZ_API
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
uint8_t ut8
Definition: lh5801.h:11
int n
Definition: mipsasm.c:19
RZ_API PJ * pj_S(PJ *j, const char *k)
Definition: pj.c:212
RZ_API void pj_raw(PJ *j, const char *k)
Definition: pj.c:7
RZ_API PJ * pj_j(PJ *j, const char *k)
Definition: pj.c:243
RZ_API PJ * pj_ko(PJ *j, const char *k)
Definition: pj.c:156
#define RZ_PRINT_JSON_DEPTH_LIMIT
Definition: rz_pj.h:4
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_r(PJ *j, const ut8 *v, size_t v_len)
Definition: pj.c:225
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API char * pj_drain(PJ *j)
Definition: pj.c:50
RZ_API PJ * pj_b(PJ *j, bool v)
Definition: pj.c:190
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API PJ * pj_i(PJ *j, int d)
Definition: pj.c:284
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_knull(PJ *j, const char *k)
Definition: pj.c:114
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_d(PJ *j, double d)
Definition: pj.c:276
RZ_API PJ * pj_f(PJ *j, float d)
Definition: pj.c:268
RZ_API PJ * pj_null(PJ *j)
Definition: pj.c:184
RZ_API PJ * pj_kf(PJ *j, const char *k, float d)
Definition: pj.c:143
struct pj_t PJ
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_n(PJ *j, ut64 n)
Definition: pj.c:252
RZ_API PJ * pj_N(PJ *j, st64 n)
Definition: pj.c:260
RZ_API PJ * pj_kr(PJ *j, const char *k, const ut8 *v, size_t v_len)
Definition: pj.c:236
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
RZ_API PJ * pj_kd(PJ *j, const char *k, double d)
Definition: pj.c:136
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
RZ_API void pj_reset(PJ *j)
Definition: pj.c:42
RZ_API PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
#define st64
Definition: rz_types_base.h:10
#define d(i)
Definition: sha256.c:44
Definition: rz_pj.h:12
char braces[RZ_PRINT_JSON_DEPTH_LIMIT]
Definition: rz_pj.h:16
bool is_first
Definition: rz_pj.h:14
int level
Definition: rz_pj.h:17
bool is_key
Definition: rz_pj.h:15
RzStrBuf sb
Definition: rz_pj.h:13
ut64(WINAPI *w32_GetEnabledXStateFeatures)()