VSF Documented
vsf_json.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_JSON_H__
19#define __VSF_JSON_H__
20
21/*============================ INCLUDES ======================================*/
23
24#if VSF_USE_JSON == ENABLED
25
27
28#if defined(__VSF_JSON_CLASS_IMPLEMENT)
29# define __VSF_CLASS_IMPLEMENT__
30# undef __VSF_JSON_CLASS_IMPLEMENT
31#elif defined(__VSF_JSON_CLASS_INHERIT__)
32# define __VSF_CLASS_INHERIT__
33# undef __VSF_JSON_CLASS_INHERIT__
34#endif
35
36#include "utilities/ooc_class.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*============================ MACROS ========================================*/
43/*============================ MACROFIED FUNCTIONS ===========================*/
44
45#define vsf_json_set_object(__c, __key, ...) \
46 do { \
47 int len = vsf_json_set_key((__c), (__key)); \
48 if (len < 0) break; \
49 (__c)->first = true; \
50 len = vsf_json_write_str((__c), "{", 1); \
51 if (len < 0) break; \
52 __VA_ARGS__; \
53 len = vsf_json_write_str((__c), "}", 1); \
54 if (len < 0) break; \
55 } while (0)
56
57
58#define vsf_json_set_array(__c, __key, ...) \
59 do { \
60 int len = vsf_json_set_key((__c), (__key)); \
61 if (len < 0) break; \
62 (__c)->first = true; \
63 len = vsf_json_write_str((__c), "[", 1); \
64 if (len < 0) break; \
65 __VA_ARGS__; \
66 len = vsf_json_write_str((__c), "]", 1); \
67 if (len < 0) break; \
68 } while (0)
69
70/*============================ TYPES =========================================*/
71
80};
82
84 private_member(
85 char *ptr;
87 bool first;
88 )
89};
90
92 public_member(
93 union {
94 void *param;
95 uint32_t len;
96 };
97 int (*write_str)(void *, char *, int);
98
99 bool first;
100 bool result;
102};
103
104/*============================ GLOBAL VARIABLES ==============================*/
105/*============================ PROTOTYPES ====================================*/
106
109extern char * vsf_json_get(const char *json, const char *key);
110extern int vsf_json_num_of_entry(const char *json);
111
112extern vsf_json_type_t vsf_json_get_type(const char *json);
113extern int vsf_json_get_string(const char *json, char *result, int len);
114extern int vsf_json_get_number(const char *json, double *result);
115extern int vsf_json_get_boolean(const char *json, bool *result);
116
117
118
119extern void vsf_json_constructor_init(vsf_json_constructor_t *c, void *param,
120 int (*write_str)(void *, char *, int));
121// param is vsf_mem_t *
122extern int vsf_json_constructor_buffer_write_str(void *param, char *str, int len);
123
124extern int vsf_json_write_str(vsf_json_constructor_t *c, char *buf, int len);
125extern int vsf_json_set_key(vsf_json_constructor_t *c, char *key);
126extern int vsf_json_set_string(vsf_json_constructor_t *c, char *key, char *value);
127extern int vsf_json_set_integer(vsf_json_constructor_t *c, char *key, int value);
128extern int vsf_json_set_double(vsf_json_constructor_t *c, char *key, double value);
129extern int vsf_json_set_boolean(vsf_json_constructor_t *c, char *key, bool value);
130extern int vsf_json_set_null(vsf_json_constructor_t *c, char *key);
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif // VSF_USE_JSON
137#endif // __VSF_JSON_H__
Definition vsf_json.h:91
Definition vsf_json.h:83
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned uint32_t
Definition stdint.h:9
vk_av_control_value_t value
Definition vsf_audio.h:171
vk_av_control_type_t type
Definition vsf_audio.h:170
int vsf_json_set_null(vsf_json_constructor_t *c, char *key)
Definition vsf_json.c:463
int vsf_json_write_str(vsf_json_constructor_t *c, char *buf, int len)
Definition vsf_json.c:347
int vsf_json_set_boolean(vsf_json_constructor_t *c, char *key, bool value)
Definition vsf_json.c:457
vsf_json_type_t vsf_json_enumerate_start(vsf_json_enumerator_t *e, const char *json)
Definition vsf_json.c:72
char * vsf_json_get(const char *json, const char *key)
Definition vsf_json.c:188
int vsf_json_constructor_buffer_write_str(void *param, char *str, int len)
Definition vsf_json.c:469
int vsf_json_get_string(const char *json, char *result, int len)
Definition vsf_json.c:250
int vsf_json_set_double(vsf_json_constructor_t *c, char *key, double value)
Definition vsf_json.c:444
int vsf_json_get_boolean(const char *json, bool *result)
Definition vsf_json.c:317
int vsf_json_num_of_entry(const char *json)
Definition vsf_json.c:175
int vsf_json_set_key(vsf_json_constructor_t *c, char *key)
Definition vsf_json.c:367
int vsf_json_set_integer(vsf_json_constructor_t *c, char *key, int value)
Definition vsf_json.c:431
int vsf_json_set_string(vsf_json_constructor_t *c, char *key, char *value)
Definition vsf_json.c:392
vsf_json_type_t
Definition vsf_json.h:72
@ VSF_JSON_TYPE_STRING
Definition vsf_json.h:76
@ VSF_JSON_TYPE_BOOLEAN
Definition vsf_json.h:78
@ VSF_JSON_TYPE_ARRAY
Definition vsf_json.h:75
@ VSF_JSON_TYPE_NULL
Definition vsf_json.h:79
@ VSF_JSON_TYPE_INVALID
Definition vsf_json.h:73
@ VSF_JSON_TYPE_NUMBER
Definition vsf_json.h:77
@ VSF_JSON_TYPE_OBJECT
Definition vsf_json.h:74
void vsf_json_constructor_init(vsf_json_constructor_t *c, void *param, int(*write_str)(void *, char *, int))
Definition vsf_json.c:334
int vsf_json_get_number(const char *json, double *result)
Definition vsf_json.c:304
char * vsf_json_enumerate_next(vsf_json_enumerator_t *e)
Definition vsf_json.c:90
vsf_json_type_t vsf_json_get_type(const char *json)
Definition vsf_json.c:43