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
53#define GP_JSON_WRITER_INIT(vout, vout_priv) { \
54 .err_print = GP_JSON_ERR_PRINT, \
55 .err_print_priv = GP_JSON_ERR_PRINT_PRIV, \
56 .out = vout, \
57 .out_priv = vout_priv \
58}
59
66
73
81static inline char *gp_json_writer_vec(gp_json_writer *self)
82{
83 return self->out_priv;
84}
85
98
107
115static inline int gp_json_writer_err(gp_json_writer *self)
116{
117 return !!self->err[0];
118}
119
132int gp_json_obj_start(gp_json_writer *self, const char *id);
133
144
157int gp_json_arr_start(gp_json_writer *self, const char *id);
158
169
181int gp_json_null_add(gp_json_writer *self, const char *id);
182
195int gp_json_int_add(gp_json_writer *self, const char *id, long val);
196
209int gp_json_bool_add(gp_json_writer *self, const char *id, int val);
210
223int gp_json_float_add(gp_json_writer *self, const char *id, double val);
224
237int gp_json_str_add(gp_json_writer *self, const char *id, const char *str);
238
249
250#endif /* GP_JSON_WRITER_H */
Common JSON reader/writer definitions.
#define GP_JSON_RECURSION_MAX
Maximal recursion depth allowed.
#define GP_JSON_ERR_MAX
Maximal error message length.
int gp_json_obj_finish(gp_json_writer *self)
Finishes a JSON object.
gp_json_writer * gp_json_writer_file_open(const char *path)
Allocates a JSON file writer.
gp_json_writer * gp_json_writer_vec_new(void)
Allocates a JSON writer with a vector as a storage.
int gp_json_writer_finish(gp_json_writer *self)
Finalizes json writer.
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 a JSON array.
int gp_json_writer_file_close(gp_json_writer *self)
Closes and frees a JSON file writer.
int gp_json_obj_start(gp_json_writer *self, const char *id)
Starts a 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)