Freeciv-3.3
Loading...
Searching...
No Matches
dataio_raw.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_RAW_H
14#define FC__DATAIO_RAW_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "bitvector.h"
22#include "support.h" /* bool type */
23
24struct cm_parameter;
25struct worklist;
26struct unit_order;
27struct requirement;
28struct act_prob;
29
30struct data_in {
31 const void *src;
33};
34
36 void *dest;
38 bool too_short; /* set to 1 if try to read past end */
39};
40
41/* Used for dio_<put|get>_type() methods.
42 * NB: we only support integer handling currently. */
53
54/* What a location inside a packet is. */
56 /* A field. Addressed by its name. */
58 /* An array element. Addressed by its number. */
60};
61
62/* Address of a location inside a packet. */
63struct plocation {
64 /* The location kind. */
66
67 union {
68 // PTZ190716 int is too small for indexing
69 /* Used if this is an array element */
70 size_t number;
71
72 /* Used if this is a field. */
73 char *name;
74 };
75
76 /* If the full address is to a location inside this this field should
77 * point to it. If this location is the final location this field should
78 * be NULL. */
80};
81
84const char *plocation_name(const struct plocation *loc);
85
86#ifdef FREECIV_JSON_CONNECTION
87#include "dataio_json.h"
88#endif
89
90/* network string conversion */
91typedef char *(*DIO_PUT_CONV_FUN) (const char *src, size_t *length);
93
94typedef bool(*DIO_GET_CONV_FUN) (char *dst, size_t ndst,
95 const char *src, size_t nsrc);
97
98bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src,
99 size_t nsrc);
100
101/* General functions */
102void dio_output_init(struct raw_data_out *dout, void *destination,
103 size_t dest_size);
105size_t dio_output_used(struct raw_data_out *dout);
106
107void dio_input_init(struct data_in *dout, const void *src, size_t src_size);
108void dio_input_rewind(struct data_in *din);
109size_t dio_input_remaining(struct data_in *din);
110bool dio_input_skip(struct data_in *din, size_t size);
111
112size_t data_type_size(enum data_type type);
113
114/* gets */
115bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest)
116 fc__attribute((nonnull (3)));
117
118bool dio_get_uint8_raw(struct data_in *din, int *dest)
119 fc__attribute((nonnull (2)));
120bool dio_get_uint16_raw(struct data_in *din, int *dest)
121 fc__attribute((nonnull (2)));
122bool dio_get_uint32_raw(struct data_in *din, int *dest)
123 fc__attribute((nonnull (2)));
124
125bool dio_get_sint8_raw(struct data_in *din, int *dest)
126 fc__attribute((nonnull (2)));
127bool dio_get_sint16_raw(struct data_in *din, int *dest)
128 fc__attribute((nonnull (2)));
129bool dio_get_sint32_raw(struct data_in *din, int *dest)
130 fc__attribute((nonnull (2)));
131
132bool dio_get_bool8_raw(struct data_in *din, bool *dest)
133 fc__attribute((nonnull (2)));
134bool dio_get_bool32_raw(struct data_in *din, bool *dest)
135 fc__attribute((nonnull (2)));
136bool dio_get_ufloat_raw(struct data_in *din, float *dest, int float_factor)
137 fc__attribute((nonnull (2)));
138bool dio_get_sfloat_raw(struct data_in *din, float *dest, int float_factor)
139 fc__attribute((nonnull (2)));
140bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size)
141 fc__attribute((nonnull (2)));
142bool dio_get_string_raw(struct data_in *din, char *dest, size_t max_dest_size)
143 fc__attribute((nonnull (2)));
144bool dio_get_cm_parameter_raw(struct data_in *din, struct cm_parameter *param)
145 fc__attribute((nonnull (2)));
146bool dio_get_worklist_raw(struct data_in *din, struct worklist *pwl)
147 fc__attribute((nonnull (2)));
148bool dio_get_unit_order_raw(struct data_in *din, struct unit_order *order)
149 fc__attribute((nonnull (2)));
151 fc__attribute((nonnull (2)));
153 struct act_prob *aprob)
154 fc__attribute((nonnull (2)));
155
156bool dio_get_uint8_vec8_raw(struct data_in *din, int **values, int stop_value)
157 fc__attribute((nonnull (2)));
158bool dio_get_uint16_vec8_raw(struct data_in *din, int **values, int stop_value)
159 fc__attribute((nonnull (2)));
160
161/* There is currently no need to escape strings in the binary protocol. */
162#define dio_get_estring_raw dio_get_string_raw
163#define dio_put_estring_raw dio_put_string_raw
164
165/* In the binary protocol, just encode the array lengths. */
166#define dio_get_arraylen_raw dio_get_uint16_raw
167#define dio_put_arraylen_raw dio_put_uint16_raw
168
169#ifndef FREECIV_JSON_CONNECTION
170
171/* Should be a function but we need some macro magic. */
172#define DIO_BV_GET(pdin, location, bv) \
173 dio_get_memory_raw((pdin), (bv).vec, sizeof((bv).vec))
174
175#define DIO_GET(f, d, l, ...) dio_get_##f##_raw(d, ## __VA_ARGS__)
176
177#endif /* FREECIV_JSON_CONNECTION */
178
179/* puts */
180int dio_put_type_raw(struct raw_data_out *dout, enum data_type type, int value);
181
182int dio_put_uint8_raw(struct raw_data_out *dout, int value);
183int dio_put_uint16_raw(struct raw_data_out *dout, int value);
184int dio_put_uint32_raw(struct raw_data_out *dout, int value);
185
186int dio_put_sint8_raw(struct raw_data_out *dout, int value);
187int dio_put_sint16_raw(struct raw_data_out *dout, int value);
188int dio_put_sint32_raw(struct raw_data_out *dout, int value);
189
190int dio_put_bool8_raw(struct raw_data_out *dout, bool value);
191int dio_put_bool32_raw(struct raw_data_out *dout, bool value);
192int dio_put_ufloat_raw(struct raw_data_out *dout, float value, int float_factor);
193int dio_put_sfloat_raw(struct raw_data_out *dout, float value, int float_factor);
194
195int dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size);
196int dio_put_string_raw(struct raw_data_out *dout, const char *value);
198 const struct cm_parameter *param);
199int dio_put_worklist_raw(struct raw_data_out *dout, const struct worklist *pwl);
201 const struct unit_order *order);
202int dio_put_requirement_raw(struct raw_data_out *dout, const struct requirement *preq);
204 const struct act_prob *aprob);
205
206int dio_put_uint8_vec8_raw(struct raw_data_out *dout, int *values, int stop_value);
207int dio_put_uint16_vec8_raw(struct raw_data_out *dout, int *values, int stop_value);
208
209#ifndef FREECIV_JSON_CONNECTION
210
211/* Should be a function but we need some macro magic. */
212#define DIO_BV_PUT(pdout, location, bv) \
213 dio_put_memory_raw((pdout), (bv).vec, sizeof((bv).vec))
214
215#define DIO_PUT(f, d, l, ...) dio_put_##f##_raw(d, ## __VA_ARGS__)
216
217#endif /* FREECIV_JSON_CONNECTION */
218
219#ifdef __cplusplus
220}
221#endif /* __cplusplus */
222
223#endif /* FC__DATAIO_RAW_H */
char * incite_cost
Definition comments.c:76
int dio_put_uint8_vec8_raw(struct raw_data_out *dout, int *values, int stop_value)
Definition dataio_raw.c:447
int dio_put_cm_parameter_raw(struct raw_data_out *dout, const struct cm_parameter *param)
Definition dataio_raw.c:533
char *(* DIO_PUT_CONV_FUN)(const char *src, size_t *length)
Definition dataio_raw.h:91
int dio_put_type_raw(struct raw_data_out *dout, enum data_type type, int value)
Definition dataio_raw.c:331
int dio_put_action_probability_raw(struct raw_data_out *dout, const struct act_prob *aprob)
int dio_put_uint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:265
bool dio_get_action_probability_raw(struct data_in *din, struct act_prob *aprob) fc__attribute((nonnull(2)))
void dio_input_init(struct data_in *dout, const void *src, size_t src_size)
Definition dataio_raw.c:202
struct plocation * plocation_field_new(char *name)
plocation_kind
Definition dataio_raw.h:55
@ PADR_FIELD
Definition dataio_raw.h:57
@ PADR_ELEMENT
Definition dataio_raw.h:59
int dio_put_uint32_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:309
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Definition dataio_raw.c:171
bool dio_get_uint8_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:598
void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun)
Definition dataio_raw.c:131
bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src, size_t nsrc)
Definition dataio_raw.c:139
bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest) fc__attribute((nonnull(3)))
Definition dataio_raw.c:661
bool dio_get_string_raw(struct data_in *din, char *dest, size_t max_dest_size) fc__attribute((nonnull(2)))
Definition dataio_raw.c:831
size_t dio_input_remaining(struct data_in *din)
Definition dataio_raw.c:221
bool(* DIO_GET_CONV_FUN)(char *dst, size_t ndst, const char *src, size_t nsrc)
Definition dataio_raw.h:94
bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size) fc__attribute((nonnull(2)))
Definition dataio_raw.c:816
int dio_put_string_raw(struct raw_data_out *dout, const char *value)
Definition dataio_raw.c:512
bool dio_get_worklist_raw(struct data_in *din, struct worklist *pwl) fc__attribute((nonnull(2)))
Definition dataio_raw.c:932
bool dio_get_uint8_vec8_raw(struct data_in *din, int **values, int stop_value) fc__attribute((nonnull(2)))
Definition dataio_raw.c:968
bool dio_get_ufloat_raw(struct data_in *din, float *dest, int float_factor) fc__attribute((nonnull(2)))
Definition dataio_raw.c:728
bool dio_get_bool8_raw(struct data_in *din, bool *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:687
bool dio_get_uint32_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:640
int dio_put_bool8_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:386
int dio_put_sint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:358
void dio_input_rewind(struct data_in *din)
Definition dataio_raw.c:213
int dio_put_requirement_raw(struct raw_data_out *dout, const struct requirement *preq)
bool dio_get_bool32_raw(struct data_in *din, bool *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:707
bool dio_get_sfloat_raw(struct data_in *din, float *dest, int float_factor) fc__attribute((nonnull(2)))
Definition dataio_raw.c:744
bool dio_get_requirement_raw(struct data_in *din, struct requirement *preq) fc__attribute((nonnull(2)))
int dio_put_sint32_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:374
bool dio_get_cm_parameter_raw(struct data_in *din, struct cm_parameter *param) fc__attribute((nonnull(2)))
Definition dataio_raw.c:868
int dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size)
Definition dataio_raw.c:499
bool dio_get_sint32_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:795
int dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:398
bool dio_get_uint16_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:619
int dio_put_uint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:287
bool dio_input_skip(struct data_in *din, size_t size)
Definition dataio_raw.c:252
size_t data_type_size(enum data_type type)
Definition dataio_raw.c:229
data_type
Definition dataio_raw.h:43
@ DIOT_UINT8
Definition dataio_raw.h:44
@ DIOT_UINT32
Definition dataio_raw.h:46
@ DIOT_UINT16
Definition dataio_raw.h:45
@ DIOT_LAST
Definition dataio_raw.h:51
@ DIOT_SINT32
Definition dataio_raw.h:49
@ DIOT_SINT8
Definition dataio_raw.h:47
@ DIOT_SINT16
Definition dataio_raw.h:48
struct plocation * plocation_elem_new(int number)
int dio_put_unit_order_raw(struct raw_data_out *dout, const struct unit_order *order)
Definition dataio_raw.c:560
int dio_put_ufloat_raw(struct raw_data_out *dout, float value, int float_factor)
Definition dataio_raw.c:412
size_t dio_output_used(struct raw_data_out *dout)
Definition dataio_raw.c:184
bool dio_get_sint8_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:759
int dio_put_uint16_vec8_raw(struct raw_data_out *dout, int *values, int stop_value)
Definition dataio_raw.c:474
bool dio_get_unit_order_raw(struct data_in *din, struct unit_order *order) fc__attribute((nonnull(2)))
Definition dataio_raw.c:906
int dio_put_sfloat_raw(struct raw_data_out *dout, float value, int float_factor)
Definition dataio_raw.c:429
void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun)
Definition dataio_raw.c:102
int dio_put_sint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:366
const char * plocation_name(const struct plocation *loc)
void dio_output_rewind(struct raw_data_out *dout)
Definition dataio_raw.c:193
bool dio_get_uint16_vec8_raw(struct data_in *din, int **values, int stop_value) fc__attribute((nonnull(2)))
Definition dataio_raw.c:993
bool dio_get_sint16_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:777
int dio_put_worklist_raw(struct raw_data_out *dout, const struct worklist *pwl)
Definition dataio_raw.c:579
struct tile * loc
Definition citydlg.c:227
GType type
Definition repodlgs.c:1313
const char * name
Definition inputfile.c:127
size_t size
Definition specvec.h:72
const void * src
Definition dataio_raw.h:31
size_t src_size
Definition dataio_raw.h:32
size_t current
Definition dataio_raw.h:32
enum plocation_kind kind
Definition dataio_raw.h:65
size_t number
Definition dataio_raw.h:70
struct plocation * sub_location
Definition dataio_raw.h:79
char * name
Definition dataio_raw.h:73
void * dest
Definition dataio_raw.h:36
size_t used
Definition dataio_raw.h:37
size_t dest_size
Definition dataio_raw.h:37
size_t current
Definition dataio_raw.h:37
#define fc__attribute(x)
Definition support.h:99
#define bool
Definition support.h:71