Freeciv-3.3: /fast/freeciv/nightly/main/common/networking/dataio_json.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
dataio_json.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__DATAIO_JSON_H
14#define FC__DATAIO_JSON_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20#include <jansson.h>
21
22/* utility */
23#include "bitvector.h"
24#include "support.h" /* bool type */
25
26/* common/networking */
27#include "connection.h"
28
29struct cm_parameter;
30struct unit_order;
31struct worklist;
32struct requirement;
33
34 struct json_data_out {
35 struct raw_data_out raw;
36 json_t *json;
37};
38
39/* gets */
40 bool dio_get_type_json(struct data_in *din, enum data_type type, int *dest)
41 fc__attribute((nonnull (3)));
42
43 bool dio_get_uint8_json(struct connection *pc, struct data_in *din,
44 const struct plocation *location, int *dest)
45 fc__attribute((nonnull (4)));
46 bool dio_get_uint16_json(struct connection *pc, struct data_in *din,
47 const struct plocation *location, int *dest)
48 fc__attribute((nonnull (4)));
49 bool dio_get_uint32_json(struct connection *pc, struct data_in *din,
50 const struct plocation *location, int *dest)
51 fc__attribute((nonnull (4)));
52
53 bool dio_get_sint8_json(struct connection *pc, struct data_in *din,
54 const struct plocation *location, int *dest)
55 fc__attribute((nonnull (4)));
56 bool dio_get_sint16_json(struct connection *pc, struct data_in *din,
57 const struct plocation *location, int *dest)
58 fc__attribute((nonnull (4)));
59 bool dio_get_sint32_json(struct connection *pc, struct data_in *din,
60 const struct plocation *location, int *dest)
61 fc__attribute((nonnull (4)));
62
63 bool dio_get_bool8_json(struct connection *pc, struct data_in *din,
64 const struct plocation *location, bool *dest)
65 fc__attribute((nonnull (4)));
66 bool dio_get_bool32_json(struct connection *pc, struct data_in *din,
67 const struct plocation *location, bool *dest)
68 fc__attribute((nonnull (4)));
69 bool dio_get_ufloat_json(struct connection *pc, struct data_in *din,
70 const struct plocation *location,
71 float *dest, int float_factor)
72 fc__attribute((nonnull (4)));
73 bool dio_get_sfloat_json(struct connection *pc, struct data_in *din,
74 const struct plocation *location,
75 float *dest, int float_factor)
76 fc__attribute((nonnull (4)));
77 bool dio_get_memory_json(struct connection *pc, struct data_in *din,
78 struct plocation *location,
79 void *dest, size_t dest_size)
80 fc__attribute((nonnull (4)));
81 bool dio_get_string_json(struct connection *pc, struct data_in *din,
82 const struct plocation *location,
83 char *dest, size_t max_dest_size)
84 fc__attribute((nonnull (4)));
85 bool dio_get_estring_json(struct connection *pc, struct data_in *din,
86 const struct plocation *location,
87 char *dest, size_t max_dest_size)
88 fc__attribute((nonnull (4)));
89 bool dio_get_cm_parameter_json(struct connection *pc, struct data_in *din,
90 struct plocation *location,
91 struct cm_parameter *param)
92 fc__attribute((nonnull (4)));
93 bool dio_get_worklist_json(struct connection *pc, struct data_in *din,
94 struct plocation *location,
95 struct worklist *pwl)
96 fc__attribute((nonnull (4)));
97 bool dio_get_unit_order_json(struct connection *pc, struct data_in *din,
98 struct plocation *location,
99 struct unit_order *order)
100 fc__attribute((nonnull (4)));
101 bool dio_get_requirement_json(struct connection *pc, struct data_in *din,
102 const struct plocation *location,
103 struct requirement *preq)
104 fc__attribute((nonnull (4)));
105 bool dio_get_action_probability_json(struct connection *pc, struct data_in *din,
106 const struct plocation *location,
107 struct act_prob *prob)
108 fc__attribute((nonnull (4)));
109
110 bool dio_get_arraylen_json(struct connection *pc, struct data_in *din,
111 const struct plocation *location, int *dest)
112 fc__attribute((nonnull (4)));
113 bool dio_get_uint8_vec8_json(struct connection *pc, struct data_in *din,
114 const struct plocation *location,
115 int **values, int stop_value)
116 fc__attribute((nonnull (4)));
117 bool dio_get_uint16_vec8_json(struct connection *pc, struct data_in *din,
118 const struct plocation *location,
119 int **values, int stop_value)
120 fc__attribute((nonnull (4)));
121
122/* Should be a function but we need some macro magic. */
123#define DIO_BV_GET(pdin, location, bv) \
124 dio_get_memory_json(pc, pdin, location, \
125 (bv).vec, sizeof((bv).vec))
126
127#define DIO_GET(f, d, l, ...) \
128 dio_get_##f##_json(pc, d, l, ## __VA_ARGS__)
129
130/* puts */
131 int dio_put_farray_json(struct json_data_out *dout,
132 const struct plocation *location, int size);
133
134 int dio_put_type_json(struct json_data_out *dout, enum data_type type,
135 const struct plocation *location,
136 int value);
137
138 int dio_put_uint8_json(struct json_data_out *dout,
139 const struct plocation *location, int value);
140 int dio_put_sint8_json(struct json_data_out *dout,
141 const struct plocation *location, int value);
142 int dio_put_uint16_json(struct json_data_out *dout,
143 const struct plocation *location, int value);
144 int dio_put_sint16_json(struct json_data_out *dout,
145 const struct plocation *location, int value);
146 int dio_put_uint32_json(struct json_data_out *dout,
147 const struct plocation *location, int value);
148 int dio_put_sint32_json(struct json_data_out *dout,
149 const struct plocation *location, int value);
150 int dio_put_bool8_json(struct json_data_out *dout,
151 const struct plocation *location, bool value);
152 int dio_put_bool32_json(struct json_data_out *dout,
153 const struct plocation *location, bool value);
154 int dio_put_ufloat_json(struct json_data_out *dout,
155 const struct plocation *location,
156 float value, int float_factor);
157 int dio_put_sfloat_json(struct json_data_out *dout,
158 const struct plocation *location,
159 float value, int float_factor);
160
161 int dio_put_memory_json(struct json_data_out *dout,
162 struct plocation *location,
163 const void *value, size_t size);
164 int dio_put_string_json(struct json_data_out *dout,
165 const struct plocation *location,
166 const char *value);
167 int dio_put_estring_json(struct json_data_out *dout,
168 const struct plocation *location,
169 const char *value);
170 int dio_put_cm_parameter_json(struct json_data_out *dout,
171 struct plocation *location,
172 const struct cm_parameter *order);
173 int dio_put_unit_order_json(struct json_data_out *dout,
174 struct plocation *location,
175 const struct unit_order *order);
176 int dio_put_worklist_json(struct json_data_out *dout,
177 struct plocation *location,
178 const struct worklist *pwl);
179 int dio_put_requirement_json(struct json_data_out *dout,
180 const struct plocation *location,
181 const struct requirement *preq);
182 int dio_put_action_probability_json(struct json_data_out *dout,
183 const struct plocation *location,
184 const struct act_prob *prob);
185
186 int dio_put_arraylen_json(struct json_data_out *dout,
187 const struct plocation *location, int size);
188 int dio_put_uint8_vec8_json(struct json_data_out *dout,
189 const struct plocation *location,
190 int *values, int stop_value);
191 int dio_put_uint16_vec8_json(struct json_data_out *dout,
192 const struct plocation *location,
193 int *values, int stop_value);
194
195/* Should be a function but we need some macro magic. */
196#define DIO_BV_PUT(pdout, location, bv) \
197 dio_put_memory_json((pdout), location, (bv).vec, sizeof((bv).vec))
198
199#define DIO_PUT(f, d, l, ...) \
200 dio_put_##f##_json(d, l, ## __VA_ARGS__)
201
202#ifdef __cplusplus
203}
204#endif /* __cplusplus */
205
206#endif /* FC__DATAIO_JSON_H */
bitvector.h
incite_cost
char * incite_cost
Definition comments.c:74
connection.h
dio_put_unit_order_json
int dio_put_unit_order_json(struct json_data_out *dout, struct plocation *location, const struct unit_order *order)
dio_get_uint8_vec8_json
bool dio_get_uint8_vec8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int **values, int stop_value) fc__attribute((nonnull(4)))
dio_get_type_json
bool dio_get_type_json(struct data_in *din, enum data_type type, int *dest) fc__attribute((nonnull(3)))
dio_get_uint8_json
bool dio_get_uint8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_type_json
int dio_put_type_json(struct json_data_out *dout, enum data_type type, const struct plocation *location, int value)
dio_put_uint8_vec8_json
int dio_put_uint8_vec8_json(struct json_data_out *dout, const struct plocation *location, int *values, int stop_value)
dio_get_cm_parameter_json
bool dio_get_cm_parameter_json(struct connection *pc, struct data_in *din, struct plocation *location, struct cm_parameter *param) fc__attribute((nonnull(4)))
dio_get_requirement_json
bool dio_get_requirement_json(struct connection *pc, struct data_in *din, const struct plocation *location, struct requirement *preq) fc__attribute((nonnull(4)))
dio_put_worklist_json
int dio_put_worklist_json(struct json_data_out *dout, struct plocation *location, const struct worklist *pwl)
dio_put_uint32_json
int dio_put_uint32_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_get_estring_json
bool dio_get_estring_json(struct connection *pc, struct data_in *din, const struct plocation *location, char *dest, size_t max_dest_size) fc__attribute((nonnull(4)))
dio_put_uint16_vec8_json
int dio_put_uint16_vec8_json(struct json_data_out *dout, const struct plocation *location, int *values, int stop_value)
dio_get_uint32_json
bool dio_get_uint32_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_get_memory_json
bool dio_get_memory_json(struct connection *pc, struct data_in *din, struct plocation *location, void *dest, size_t dest_size) fc__attribute((nonnull(4)))
dio_get_uint16_vec8_json
bool dio_get_uint16_vec8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int **values, int stop_value) fc__attribute((nonnull(4)))
dio_put_uint16_json
int dio_put_uint16_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_get_sint8_json
bool dio_get_sint8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_memory_json
int dio_put_memory_json(struct json_data_out *dout, struct plocation *location, const void *value, size_t size)
dio_get_sint32_json
bool dio_get_sint32_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_arraylen_json
int dio_put_arraylen_json(struct json_data_out *dout, const struct plocation *location, int size)
dio_put_uint8_json
int dio_put_uint8_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_farray_json
int dio_put_farray_json(struct json_data_out *dout, const struct plocation *location, int size)
dio_put_bool8_json
int dio_put_bool8_json(struct json_data_out *dout, const struct plocation *location, bool value)
dio_put_sint32_json
int dio_put_sint32_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_estring_json
int dio_put_estring_json(struct json_data_out *dout, const struct plocation *location, const char *value)
dio_put_action_probability_json
int dio_put_action_probability_json(struct json_data_out *dout, const struct plocation *location, const struct act_prob *prob)
dio_get_arraylen_json
bool dio_get_arraylen_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_get_worklist_json
bool dio_get_worklist_json(struct connection *pc, struct data_in *din, struct plocation *location, struct worklist *pwl) fc__attribute((nonnull(4)))
dio_get_sfloat_json
bool dio_get_sfloat_json(struct connection *pc, struct data_in *din, const struct plocation *location, float *dest, int float_factor) fc__attribute((nonnull(4)))
dio_put_bool32_json
int dio_put_bool32_json(struct json_data_out *dout, const struct plocation *location, bool value)
dio_get_bool32_json
bool dio_get_bool32_json(struct connection *pc, struct data_in *din, const struct plocation *location, bool *dest) fc__attribute((nonnull(4)))
dio_get_ufloat_json
bool dio_get_ufloat_json(struct connection *pc, struct data_in *din, const struct plocation *location, float *dest, int float_factor) fc__attribute((nonnull(4)))
dio_get_bool8_json
bool dio_get_bool8_json(struct connection *pc, struct data_in *din, const struct plocation *location, bool *dest) fc__attribute((nonnull(4)))
dio_get_unit_order_json
bool dio_get_unit_order_json(struct connection *pc, struct data_in *din, struct plocation *location, struct unit_order *order) fc__attribute((nonnull(4)))
dio_put_sfloat_json
int dio_put_sfloat_json(struct json_data_out *dout, const struct plocation *location, float value, int float_factor)
dio_put_requirement_json
int dio_put_requirement_json(struct json_data_out *dout, const struct plocation *location, const struct requirement *preq)
dio_put_sint8_json
int dio_put_sint8_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_sint16_json
int dio_put_sint16_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_ufloat_json
int dio_put_ufloat_json(struct json_data_out *dout, const struct plocation *location, float value, int float_factor)
dio_get_sint16_json
bool dio_get_sint16_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_string_json
int dio_put_string_json(struct json_data_out *dout, const struct plocation *location, const char *value)
dio_get_action_probability_json
bool dio_get_action_probability_json(struct connection *pc, struct data_in *din, const struct plocation *location, struct act_prob *prob) fc__attribute((nonnull(4)))
dio_get_uint16_json
bool dio_get_uint16_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_cm_parameter_json
int dio_put_cm_parameter_json(struct json_data_out *dout, struct plocation *location, const struct cm_parameter *order)
dio_get_string_json
bool dio_get_string_json(struct connection *pc, struct data_in *din, const struct plocation *location, char *dest, size_t max_dest_size) fc__attribute((nonnull(4)))
data_type
data_type
Definition dataio_raw.h:43
type
GType type
Definition repodlgs.c:1313
size
size_t size
Definition specvec.h:72
act_prob
Definition fc_types.h:1250
cm_parameter
Definition cm.h:40
connection
Definition connection.h:136
data_in
Definition dataio_raw.h:30
json_data_out
Definition dataio_json.h:34
json_data_out::json
json_t * json
Definition dataio_json.h:36
json_data_out::raw
struct raw_data_out raw
Definition dataio_json.h:35
plocation
Definition dataio_raw.h:63
raw_data_out
Definition dataio_raw.h:35
raw_data_out::dest
void * dest
Definition dataio_raw.h:36
raw_data_out::dest_size
size_t dest_size
Definition dataio_raw.h:37
requirement
Definition requirements.h:81
unit_order
Definition unit.h:93
worklist
Definition worklist.h:28
support.h
fc__attribute
#define fc__attribute(x)
Definition support.h:99