GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_json_writer.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2021-2022 Cyril Hrubis <metan@ucw.cz>
4 */
5
24#ifndef GP_JSON_WRITER_H
25#define GP_JSON_WRITER_H
26
28
31 unsigned int depth;
32 char depth_type[GP_JSON_RECURSION_MAX/8];
33 char depth_first[GP_JSON_RECURSION_MAX/8];
34
36 void (*err_print)(void *err_print_priv, const char *line);
37 void *err_print_priv;
38 char err[GP_JSON_ERR_MAX];
39
41 int (*out)(struct gp_json_writer *self, const char *buf, size_t buf_size);
42 void *out_priv;
43};
44
45#define GP_JSON_WRITER_INIT(out_, out_priv_) { \
46 .err_print = GP_JSON_ERR_PRINT, \
47 .err_print_priv = GP_JSON_ERR_PRINT_PRIV, \
48 .out = out_, \
49 .out_priv = out_priv_ \
50}
51
58
65
71static inline char *gp_json_writer_vec(gp_json_writer *self)
72{
73 return self->out_priv;
74}
75
81static inline int gp_json_writer_err(gp_json_writer *self)
82{
83 return !!self->err[0];
84}
85
92int gp_json_obj_start(gp_json_writer *self, const char *id);
93
100
107int gp_json_arr_start(gp_json_writer *self, const char *id);
108
115
122int gp_json_null_add(gp_json_writer *self, const char *id);
123
130int gp_json_int_add(gp_json_writer *self, const char *id, long val);
131
138int gp_json_bool_add(gp_json_writer *self, const char *id, int val);
139
146int gp_json_float_add(gp_json_writer *self, const char *id, double val);
147
154int gp_json_str_add(gp_json_writer *self, const char *id, const char *str);
155
166
167#endif /* GP_JSON_WRITER_H */
Common JSON reader/writer definitions.
int gp_json_obj_finish(gp_json_writer *self)
Finishes a JSON object.
int gp_json_finish(gp_json_writer *self)
Finalizes json writer.
gp_json_writer * gp_json_writer_vec_new(void)
Allocates a JSON writer with a vector as a storage.
int gp_json_bool_add(gp_json_writer *self, const char *id, int val)
Adds a bool value.
static int gp_json_writer_err(gp_json_writer *self)
Returns true if writer error happened.
void gp_json_writer_vec_free(gp_json_writer *self)
Frees a JSON writer with a vector as a storage.
int gp_json_null_add(gp_json_writer *self, const char *id)
Adds a null value.
int gp_json_arr_finish(gp_json_writer *self)
Finishes a JSON array.
int gp_json_str_add(gp_json_writer *self, const char *id, const char *str)
Adds a string value.
int gp_json_float_add(gp_json_writer *self, const char *id, double val)
Adds a float value.
int gp_json_int_add(gp_json_writer *self, const char *id, long val)
Adds an integer value.
int gp_json_arr_start(gp_json_writer *self, const char *id)
Starts an json array.
int gp_json_obj_start(gp_json_writer *self, const char *id)
Starts an JSON object.
static char * gp_json_writer_vec(gp_json_writer *self)
Returns a pointer to a vector storage.
A JSON writer.
int(* out)(struct gp_json_writer *self, const char *buf, size_t buf_size)
void(* err_print)(void *err_print_priv, const char *line)