| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
json_dumper.h
Go to the documentation of this file.
1
12
13#ifndef __JSON_DUMPER_H__
14#define __JSON_DUMPER_H__
15
16#include "ws_symbol_export.h"
17
18#include <inttypes.h>
19#include <stdbool.h>
20#include <stdio.h>
21
22#include <glib.h>
23
24#ifdef __cplusplus
25 extern "C" {
26#endif
27
54
56#define JSON_DUMPER_MAX_DEPTH 1100
60 typedef struct json_dumper {
61 FILE *output_file;
62 GString *output_string;
63#define JSON_DUMPER_FLAGS_PRETTY_PRINT (1 << 0)
64#define JSON_DUMPER_DOT_TO_UNDERSCORE (1 << 1)
65#define JSON_DUMPER_FLAGS_NO_DEBUG (1 << 17)
66 int flags;
67 /* For internal use; initialize with zeroes. */
68 unsigned current_depth;
69 int base64_state;
70 int base64_save;
71 uint8_t state[JSON_DUMPER_MAX_DEPTH];
72 /* Internal write buffer */
73#define JD_BUF_SIZE 8192
74 char buf[JD_BUF_SIZE];
75 size_t buf_pos;
76} json_dumper;
77
85WS_DLL_PUBLIC void
86 json_dumper_begin_object(json_dumper *dumper);
87
96WS_DLL_PUBLIC void
97 json_dumper_set_member_name(json_dumper *dumper, const char *name);
98
99WS_DLL_PUBLIC void
100 json_dumper_set_member_name_noesc(json_dumper *dumper, const char *name, size_t len);
101
109#define json_dumper_set_member_name_const(dumper, literal) \
110 json_dumper_set_member_name_noesc(dumper, literal, sizeof(literal) - 1)
111
119WS_DLL_PUBLIC void
120 json_dumper_end_object(json_dumper *dumper);
121
129WS_DLL_PUBLIC void
130 json_dumper_begin_array(json_dumper *dumper);
131
139WS_DLL_PUBLIC void
140 json_dumper_end_array(json_dumper *dumper);
141
150WS_DLL_PUBLIC void
151 json_dumper_value_string(json_dumper *dumper, const char *value);
152
163WS_DLL_PUBLIC void
164 json_dumper_value_string_noesc(json_dumper *dumper, const char *value, size_t len);
165
174WS_DLL_PUBLIC void
175 json_dumper_value_double(json_dumper *dumper, double value);
176
186WS_DLL_PUBLIC void
187 json_dumper_value_anyf(json_dumper *dumper, const char *format, ...)
188G_GNUC_PRINTF(2, 3);
189
201WS_DLL_PUBLIC void
202json_dumper_value_va_list(json_dumper *dumper, const char *format, va_list ap);
203
213WS_DLL_PUBLIC void
214json_dumper_value_literal(json_dumper *dumper, const char *literal, size_t len);
215
222WS_DLL_PUBLIC void
223json_dumper_value_int(json_dumper *dumper, int64_t value);
224
231WS_DLL_PUBLIC void
232json_dumper_value_uint(json_dumper *dumper, uint64_t value);
233
241WS_DLL_PUBLIC void
242json_dumper_begin_base64(json_dumper *dumper);
243
251WS_DLL_PUBLIC void
252json_dumper_end_base64(json_dumper *dumper);
253
263WS_DLL_PUBLIC void
264json_dumper_write_base64(json_dumper *dumper, const unsigned char *data, size_t len);
265
274WS_DLL_PUBLIC bool
275json_dumper_finish(json_dumper *dumper);
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif /* __JSON_DUMPER_H__ */
282
283/*
284 * Editor modelines - https://www.wireshark.org/tools/modelines.html
285 *
286 * Local variables:
287 * c-basic-offset: 4
288 * tab-width: 8
289 * indent-tabs-mode: nil
290 * End:
291 *
292 * vi: set shiftwidth=4 tabstop=8 expandtab:
293 * :indentSize=4:tabSize=8:noTabs=true:
294 */
json_dumper_set_member_name_noesc
WS_DLL_PUBLIC void json_dumper_set_member_name_noesc(json_dumper *dumper, const char *name, size_t len)
Definition json_dumper.c:557
json_dumper_value_double
WS_DLL_PUBLIC void json_dumper_value_double(json_dumper *dumper, double value)
Writes a double-precision numeric value to the JSON output.
Definition json_dumper.c:725
json_dumper_value_string_noesc
WS_DLL_PUBLIC void json_dumper_value_string_noesc(json_dumper *dumper, const char *value, size_t len)
Writes a string value that is known to not require JSON escaping.
Definition json_dumper.c:707
json_dumper_set_member_name
WS_DLL_PUBLIC void json_dumper_set_member_name(json_dumper *dumper, const char *name)
Sets the name of the next member in a JSON object.
Definition json_dumper.c:527
JSON_DUMPER_MAX_DEPTH
#define JSON_DUMPER_MAX_DEPTH
Definition json_dumper.h:56
json_dumper_end_object
WS_DLL_PUBLIC void json_dumper_end_object(json_dumper *dumper)
Ends the current JSON object.
Definition json_dumper.c:587
json_dumper_end_array
WS_DLL_PUBLIC void json_dumper_end_array(json_dumper *dumper)
Ends the current JSON array.
Definition json_dumper.c:599
json_dumper_begin_object
WS_DLL_PUBLIC void json_dumper_begin_object(json_dumper *dumper)
Begins a new JSON object.
Definition json_dumper.c:521
json_dumper_value_string
WS_DLL_PUBLIC void json_dumper_value_string(json_dumper *dumper, const char *value)
Writes a string value to the JSON output.
Definition json_dumper.c:691
json_dumper_value_anyf
WS_DLL_PUBLIC void json_dumper_value_anyf(json_dumper *dumper, const char *format,...)
Writes a formatted literal value to the JSON output.
Definition json_dumper.c:764
json_dumper_begin_array
WS_DLL_PUBLIC void json_dumper_begin_array(json_dumper *dumper)
Begins a new JSON array.
Definition json_dumper.c:593
json_dumper
State and configuration for incrementally writing JSON output to a file or string.
Definition json_dumper.h:60
json_dumper::buf
char buf[8192]
Definition json_dumper.h:74
json_dumper::base64_save
int base64_save
Definition json_dumper.h:70
json_dumper::base64_state
int base64_state
Definition json_dumper.h:69
json_dumper::output_file
FILE * output_file
Definition json_dumper.h:61
json_dumper::flags
int flags
Definition json_dumper.h:66
json_dumper::state
uint8_t state[1100]
Definition json_dumper.h:71
json_dumper::current_depth
unsigned current_depth
Definition json_dumper.h:68
json_dumper::buf_pos
size_t buf_pos
Definition json_dumper.h:75
json_dumper::output_string
GString * output_string
Definition json_dumper.h:62