]> git.proxmox.com Git - mirror_iproute2.git/blame - include/json_writer.h
ss: add AF_XDP support
[mirror_iproute2.git] / include / json_writer.h
CommitLineData
d9d8c839 1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
fcc16c22
SH
2/*
3 * Simple streaming JSON writer
4 *
5 * This takes care of the annoying bits of JSON syntax like the commas
6 * after elements
7 *
fcc16c22
SH
8 * Authors: Stephen Hemminger <stephen@networkplumber.org>
9 */
10
11#ifndef _JSON_WRITER_H_
12#define _JSON_WRITER_H_
13
14#include <stdbool.h>
15#include <stdint.h>
16
17/* Opaque class structure */
18typedef struct json_writer json_writer_t;
19
20/* Create a new JSON stream */
21json_writer_t *jsonw_new(FILE *f);
22/* End output to JSON stream */
23void jsonw_destroy(json_writer_t **self_p);
24
25/* Cause output to have pretty whitespace */
26void jsonw_pretty(json_writer_t *self, bool on);
27
28/* Add property name */
29void jsonw_name(json_writer_t *self, const char *name);
30
31/* Add value */
5d5586b0 32__attribute__((format(printf, 2, 3)))
7252f16b 33void jsonw_printf(json_writer_t *self, const char *fmt, ...);
fcc16c22
SH
34void jsonw_string(json_writer_t *self, const char *value);
35void jsonw_bool(json_writer_t *self, bool value);
36void jsonw_float(json_writer_t *self, double number);
7252f16b 37void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num);
4db2ff0d
THJ
38void jsonw_uint(json_writer_t *self, unsigned int number);
39void jsonw_u64(json_writer_t *self, uint64_t number);
8958a15c 40void jsonw_xint(json_writer_t *self, uint64_t number);
b640e85d 41void jsonw_hhu(json_writer_t *self, unsigned char num);
7252f16b 42void jsonw_hu(json_writer_t *self, unsigned short number);
4db2ff0d
THJ
43void jsonw_int(json_writer_t *self, int number);
44void jsonw_s64(json_writer_t *self, int64_t number);
fcc16c22 45void jsonw_null(json_writer_t *self);
3a1f602a
SH
46void jsonw_luint(json_writer_t *self, unsigned long num);
47void jsonw_lluint(json_writer_t *self, unsigned long long num);
fcc16c22
SH
48
49/* Useful Combinations of name and value */
50void jsonw_string_field(json_writer_t *self, const char *prop, const char *val);
51void jsonw_bool_field(json_writer_t *self, const char *prop, bool value);
52void jsonw_float_field(json_writer_t *self, const char *prop, double num);
4db2ff0d
THJ
53void jsonw_uint_field(json_writer_t *self, const char *prop, unsigned int num);
54void jsonw_u64_field(json_writer_t *self, const char *prop, uint64_t num);
8958a15c 55void jsonw_xint_field(json_writer_t *self, const char *prop, uint64_t num);
b640e85d 56void jsonw_hhu_field(json_writer_t *self, const char *prop, unsigned char num);
7252f16b 57void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num);
4db2ff0d
THJ
58void jsonw_int_field(json_writer_t *self, const char *prop, int num);
59void jsonw_s64_field(json_writer_t *self, const char *prop, int64_t num);
fcc16c22 60void jsonw_null_field(json_writer_t *self, const char *prop);
4db2ff0d 61void jsonw_luint_field(json_writer_t *self, const char *prop,
3a1f602a 62 unsigned long num);
7252f16b 63void jsonw_lluint_field(json_writer_t *self, const char *prop,
3a1f602a 64 unsigned long long num);
fcc16c22
SH
65
66/* Collections */
67void jsonw_start_object(json_writer_t *self);
68void jsonw_end_object(json_writer_t *self);
69
70void jsonw_start_array(json_writer_t *self);
71void jsonw_end_array(json_writer_t *self);
72
73/* Override default exception handling */
74typedef void (jsonw_err_handler_fn)(const char *);
75
76#endif /* _JSON_WRITER_H_ */