]>
git.proxmox.com Git - mirror_iproute2.git/blob - include/json_print.h
2 * json_print.h "print regular or json output, based on json_writer".
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Julien Fortin, <julien@cumulusnetworks.com>
12 #ifndef _JSON_PRINT_H_
13 #define _JSON_PRINT_H_
15 #include "json_writer.h"
18 json_writer_t
*get_json_writer(void);
22 * - PRINT_ANY for context based output
23 * - PRINT_FP for non json specific output
24 * - PRINT_JSON for json specific output
32 void new_json_obj(int json
);
33 void delete_json_obj(void);
34 void new_json_obj_plain(int json
);
35 void delete_json_obj_plain(void);
37 bool is_json_context(void);
39 void open_json_object(const char *str
);
40 void close_json_object(void);
41 void open_json_array(enum output_type type
, const char *delim
);
42 void close_json_array(enum output_type type
, const char *delim
);
46 #define _PRINT_FUNC(type_name, type) \
47 int print_color_##type_name(enum output_type t, \
48 enum color_attr color, \
53 static inline int print_##type_name(enum output_type t, \
58 return print_color_##type_name(t, COLOR_NONE, key, fmt, \
62 /* These functions return 0 if printing to a JSON context, number of
63 * characters printed otherwise (as calculated by printf(3)).
66 _PRINT_FUNC(s64
, int64_t)
67 _PRINT_FUNC(bool, bool)
68 _PRINT_FUNC(on_off
, bool)
69 _PRINT_FUNC(null
, const char*)
70 _PRINT_FUNC(string
, const char*)
71 _PRINT_FUNC(uint
, unsigned int)
72 _PRINT_FUNC(size
, __u32
)
73 _PRINT_FUNC(u64
, uint64_t)
74 _PRINT_FUNC(hhu
, unsigned char)
75 _PRINT_FUNC(hu
, unsigned short)
76 _PRINT_FUNC(hex
, unsigned int)
77 _PRINT_FUNC(0xhex
, unsigned long long)
78 _PRINT_FUNC(luint
, unsigned long)
79 _PRINT_FUNC(lluint
, unsigned long long)
80 _PRINT_FUNC(float, double)
83 #define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \
84 void print_##type_name##_name_value(const char *name, type value) \
86 _PRINT_NAME_VALUE_FUNC(uint, unsigned int, u);
87 _PRINT_NAME_VALUE_FUNC(string
, const char*, s
);
88 #undef _PRINT_NAME_VALUE_FUNC
90 int print_color_rate(bool use_iec
, enum output_type t
, enum color_attr color
,
91 const char *key
, const char *fmt
, unsigned long long rate
);
93 static inline int print_rate(bool use_iec
, enum output_type t
,
94 const char *key
, const char *fmt
,
95 unsigned long long rate
)
97 return print_color_rate(use_iec
, t
, COLOR_NONE
, key
, fmt
, rate
);
100 /* A backdoor to the size formatter. Please use print_size() instead. */
101 char *sprint_size(__u32 sz
, char *buf
);
103 #endif /* _JSON_PRINT_H_ */