Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/networking/dataio_raw.h Source File

Freeciv-3.1

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
30 struct data_in {
31 const void *src;
32 size_t src_size, current;
33};
34
35 struct raw_data_out {
36 void *dest;
37 size_t dest_size, used, current;
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. */
43 enum data_type {
44 DIOT_UINT8,
45 DIOT_UINT16,
46 DIOT_UINT32,
47 DIOT_SINT8,
48 DIOT_SINT16,
49 DIOT_SINT32,
50
51 DIOT_LAST
52};
53
54/* What a location inside a packet is. */
55 enum plocation_kind {
56 /* A field. Addressed by its name. */
57 PADR_FIELD,
58 /* An array element. Addressed by its number. */
59 PADR_ELEMENT
60};
61
62/* Address of a location inside a packet. */
63 struct plocation {
64 /* The location kind. */
65 enum plocation_kind kind;
66
67 union {
68 /* Used if this is an array element */
69 int number;
70
71 /* Used if this is a field. */
72 char *name;
73 };
74
75 /* If the full address is to a location inside this this field should
76 * point to it. If this location is the final location this field should
77 * be NULL. */
78 struct plocation *sub_location;
79};
80
81struct plocation *plocation_field_new(char *name);
82struct plocation *plocation_elem_new(int number);
83const char *plocation_name(const struct plocation *loc);
84
85#ifdef FREECIV_JSON_CONNECTION
86#include "dataio_json.h"
87#endif
88
89/* network string conversion */
90 typedef char *(*DIO_PUT_CONV_FUN) (const char *src, size_t *length);
91void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun);
92
93 typedef bool(*DIO_GET_CONV_FUN) (char *dst, size_t ndst,
94 const char *src, size_t nsrc);
95void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun);
96
97bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src,
98 size_t nsrc);
99
100/* General functions */
101void dio_output_init(struct raw_data_out *dout, void *destination,
102 size_t dest_size);
103void dio_output_rewind(struct raw_data_out *dout);
104size_t dio_output_used(struct raw_data_out *dout);
105
106void dio_input_init(struct data_in *dout, const void *src, size_t src_size);
107void dio_input_rewind(struct data_in *din);
108size_t dio_input_remaining(struct data_in *din);
109bool dio_input_skip(struct data_in *din, size_t size);
110
111size_t data_type_size(enum data_type type);
112
113/* gets */
114bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest)
115 fc__attribute((nonnull (3)));
116
117bool dio_get_uint8_raw(struct data_in *din, int *dest)
118 fc__attribute((nonnull (2)));
119bool dio_get_uint16_raw(struct data_in *din, int *dest)
120 fc__attribute((nonnull (2)));
121bool dio_get_uint32_raw(struct data_in *din, int *dest)
122 fc__attribute((nonnull (2)));
123
124bool dio_get_sint8_raw(struct data_in *din, int *dest)
125 fc__attribute((nonnull (2)));
126bool dio_get_sint16_raw(struct data_in *din, int *dest)
127 fc__attribute((nonnull (2)));
128bool dio_get_sint32_raw(struct data_in *din, int *dest)
129 fc__attribute((nonnull (2)));
130
131bool dio_get_bool8_raw(struct data_in *din, bool *dest)
132 fc__attribute((nonnull (2)));
133bool dio_get_bool32_raw(struct data_in *din, bool *dest)
134 fc__attribute((nonnull (2)));
135bool dio_get_ufloat_raw(struct data_in *din, float *dest, int float_factor)
136 fc__attribute((nonnull (2)));
137bool dio_get_sfloat_raw(struct data_in *din, float *dest, int float_factor)
138 fc__attribute((nonnull (2)));
139bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size)
140 fc__attribute((nonnull (2)));
141bool dio_get_string_raw(struct data_in *din, char *dest, size_t max_dest_size)
142 fc__attribute((nonnull (2)));
143bool dio_get_cm_parameter_raw(struct data_in *din, struct cm_parameter *param)
144 fc__attribute((nonnull (2)));
145bool dio_get_worklist_raw(struct data_in *din, struct worklist *pwl)
146 fc__attribute((nonnull (2)));
147bool dio_get_unit_order_raw(struct data_in *din, struct unit_order *order)
148 fc__attribute((nonnull (2)));
149bool dio_get_requirement_raw(struct data_in *din, struct requirement *preq)
150 fc__attribute((nonnull (2)));
151bool dio_get_action_probability_raw(struct data_in *din,
152 struct act_prob *aprob)
153 fc__attribute((nonnull (2)));
154
155bool dio_get_uint8_vec8_raw(struct data_in *din, int **values, int stop_value)
156 fc__attribute((nonnull (2)));
157bool dio_get_uint16_vec8_raw(struct data_in *din, int **values, int stop_value)
158 fc__attribute((nonnull (2)));
159
160/* There is currently no need to escape strings in the binary protocol. */
161#define dio_get_estring_raw dio_get_string_raw
162#define dio_put_estring_raw dio_put_string_raw
163
164#ifndef FREECIV_JSON_CONNECTION
165
166/* Should be a function but we need some macro magic. */
167#define DIO_BV_GET(pdin, location, bv) \
168 dio_get_memory_raw((pdin), (bv).vec, sizeof((bv).vec))
169
170#define DIO_GET(f, d, l, ...) dio_get_##f##_raw(d, ## __VA_ARGS__)
171
172#endif /* FREECIV_JSON_CONNECTION */
173
174/* puts */
175void dio_put_type_raw(struct raw_data_out *dout, enum data_type type, int value);
176
177void dio_put_uint8_raw(struct raw_data_out *dout, int value);
178void dio_put_uint16_raw(struct raw_data_out *dout, int value);
179void dio_put_uint32_raw(struct raw_data_out *dout, int value);
180
181void dio_put_sint8_raw(struct raw_data_out *dout, int value);
182void dio_put_sint16_raw(struct raw_data_out *dout, int value);
183void dio_put_sint32_raw(struct raw_data_out *dout, int value);
184
185void dio_put_bool8_raw(struct raw_data_out *dout, bool value);
186void dio_put_bool32_raw(struct raw_data_out *dout, bool value);
187void dio_put_ufloat_raw(struct raw_data_out *dout, float value, int float_factor);
188void dio_put_sfloat_raw(struct raw_data_out *dout, float value, int float_factor);
189
190void dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size);
191void dio_put_string_raw(struct raw_data_out *dout, const char *value);
192void dio_put_cm_parameter_raw(struct raw_data_out *dout,
193 const struct cm_parameter *param);
194void dio_put_worklist_raw(struct raw_data_out *dout, const struct worklist *pwl);
195void dio_put_unit_order_raw(struct raw_data_out *dout,
196 const struct unit_order *order);
197void dio_put_requirement_raw(struct raw_data_out *dout, const struct requirement *preq);
198void dio_put_action_probability_raw(struct raw_data_out *dout,
199 const struct act_prob *aprob);
200
201void dio_put_uint8_vec8_raw(struct raw_data_out *dout, int *values, int stop_value);
202void dio_put_uint16_vec8_raw(struct raw_data_out *dout, int *values, int stop_value);
203
204#ifndef FREECIV_JSON_CONNECTION
205
206/* Should be a function but we need some macro magic. */
207#define DIO_BV_PUT(pdout, location, bv) \
208 dio_put_memory_raw((pdout), (bv).vec, sizeof((bv).vec))
209
210#define DIO_PUT(f, d, l, ...) dio_put_##f##_raw(d, ## __VA_ARGS__)
211
212#endif /* FREECIV_JSON_CONNECTION */
213
214#ifdef __cplusplus
215}
216#endif /* __cplusplus */
217
218#endif /* FC__DATAIO_RAW_H */
bitvector.h
dataio_json.h
dio_put_cm_parameter_raw
void dio_put_cm_parameter_raw(struct raw_data_out *dout, const struct cm_parameter *param)
Definition dataio_raw.c:517
dio_put_action_probability_raw
void dio_put_action_probability_raw(struct raw_data_out *dout, const struct act_prob *aprob)
Definition dataio_raw.c:1012
dio_put_unit_order_raw
void dio_put_unit_order_raw(struct raw_data_out *dout, const struct unit_order *order)
Definition dataio_raw.c:541
DIO_PUT_CONV_FUN
char *(* DIO_PUT_CONV_FUN)(const char *src, size_t *length)
Definition dataio_raw.h:90
dio_get_action_probability_raw
bool dio_get_action_probability_raw(struct data_in *din, struct act_prob *aprob) fc__attribute((nonnull(2)))
Definition dataio_raw.c:992
dio_put_ufloat_raw
void dio_put_ufloat_raw(struct raw_data_out *dout, float value, int float_factor)
Definition dataio_raw.c:407
dio_input_init
void dio_input_init(struct data_in *dout, const void *src, size_t src_size)
Definition dataio_raw.c:202
plocation_field_new
struct plocation * plocation_field_new(char *name)
Definition dataio_raw.c:1067
plocation_kind
plocation_kind
Definition dataio_raw.h:55
PADR_FIELD
@ PADR_FIELD
Definition dataio_raw.h:57
PADR_ELEMENT
@ PADR_ELEMENT
Definition dataio_raw.h:59
dio_put_bool8_raw
void dio_put_bool8_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:381
dio_output_init
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Definition dataio_raw.c:171
dio_get_uint8_raw
bool dio_get_uint8_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:572
dio_put_uint16_raw
void dio_put_uint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:284
dio_put_sfloat_raw
void dio_put_sfloat_raw(struct raw_data_out *dout, float value, int float_factor)
Definition dataio_raw.c:424
dio_set_get_conv_callback
void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun)
Definition dataio_raw.c:131
dataio_get_conv_callback
bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src, size_t nsrc)
Definition dataio_raw.c:139
dio_get_type_raw
bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest) fc__attribute((nonnull(3)))
Definition dataio_raw.c:635
dio_get_string_raw
bool dio_get_string_raw(struct data_in *din, char *dest, size_t max_dest_size) fc__attribute((nonnull(2)))
Definition dataio_raw.c:805
dio_input_remaining
size_t dio_input_remaining(struct data_in *din)
Definition dataio_raw.c:221
dio_put_uint8_raw
void dio_put_uint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:265
dio_put_sint16_raw
void dio_put_sint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:361
DIO_GET_CONV_FUN
bool(* DIO_GET_CONV_FUN)(char *dst, size_t ndst, const char *src, size_t nsrc)
Definition dataio_raw.h:93
dio_get_memory_raw
bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size) fc__attribute((nonnull(2)))
Definition dataio_raw.c:790
dio_get_worklist_raw
bool dio_get_worklist_raw(struct data_in *din, struct worklist *pwl) fc__attribute((nonnull(2)))
Definition dataio_raw.c:906
dio_get_uint8_vec8_raw
bool dio_get_uint8_vec8_raw(struct data_in *din, int **values, int stop_value) fc__attribute((nonnull(2)))
Definition dataio_raw.c:942
dio_get_ufloat_raw
bool dio_get_ufloat_raw(struct data_in *din, float *dest, int float_factor) fc__attribute((nonnull(2)))
Definition dataio_raw.c:702
dio_get_bool8_raw
bool dio_get_bool8_raw(struct data_in *din, bool *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:661
dio_get_uint32_raw
bool dio_get_uint32_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:614
dio_put_sint32_raw
void dio_put_sint32_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:369
dio_input_rewind
void dio_input_rewind(struct data_in *din)
Definition dataio_raw.c:213
dio_put_uint32_raw
void dio_put_uint32_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:303
dio_get_bool32_raw
bool dio_get_bool32_raw(struct data_in *din, bool *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:681
dio_get_sfloat_raw
bool dio_get_sfloat_raw(struct data_in *din, float *dest, int float_factor) fc__attribute((nonnull(2)))
Definition dataio_raw.c:718
dio_get_requirement_raw
bool dio_get_requirement_raw(struct data_in *din, struct requirement *preq) fc__attribute((nonnull(2)))
Definition dataio_raw.c:1022
dio_put_memory_raw
void dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size)
Definition dataio_raw.c:488
dio_put_uint16_vec8_raw
void dio_put_uint16_vec8_raw(struct raw_data_out *dout, int *values, int stop_value)
Definition dataio_raw.c:466
dio_get_cm_parameter_raw
bool dio_get_cm_parameter_raw(struct data_in *din, struct cm_parameter *param) fc__attribute((nonnull(2)))
Definition dataio_raw.c:842
dio_put_worklist_raw
void dio_put_worklist_raw(struct raw_data_out *dout, const struct worklist *pwl)
Definition dataio_raw.c:556
dio_get_sint32_raw
bool dio_get_sint32_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:769
dio_get_uint16_raw
bool dio_get_uint16_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:593
dio_put_requirement_raw
void dio_put_requirement_raw(struct raw_data_out *dout, const struct requirement *preq)
Definition dataio_raw.c:1048
dio_input_skip
bool dio_input_skip(struct data_in *din, size_t size)
Definition dataio_raw.c:252
data_type_size
size_t data_type_size(enum data_type type)
Definition dataio_raw.c:229
dio_put_uint8_vec8_raw
void dio_put_uint8_vec8_raw(struct raw_data_out *dout, int *values, int stop_value)
Definition dataio_raw.c:442
dio_put_type_raw
void dio_put_type_raw(struct raw_data_out *dout, enum data_type type, int value)
Definition dataio_raw.c:322
data_type
data_type
Definition dataio_raw.h:43
DIOT_UINT8
@ DIOT_UINT8
Definition dataio_raw.h:44
DIOT_UINT32
@ DIOT_UINT32
Definition dataio_raw.h:46
DIOT_UINT16
@ DIOT_UINT16
Definition dataio_raw.h:45
DIOT_LAST
@ DIOT_LAST
Definition dataio_raw.h:51
DIOT_SINT32
@ DIOT_SINT32
Definition dataio_raw.h:49
DIOT_SINT8
@ DIOT_SINT8
Definition dataio_raw.h:47
DIOT_SINT16
@ DIOT_SINT16
Definition dataio_raw.h:48
plocation_elem_new
struct plocation * plocation_elem_new(int number)
Definition dataio_raw.c:1081
dio_put_string_raw
void dio_put_string_raw(struct raw_data_out *dout, const char *value)
Definition dataio_raw.c:499
dio_output_used
size_t dio_output_used(struct raw_data_out *dout)
Definition dataio_raw.c:184
dio_get_sint8_raw
bool dio_get_sint8_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:733
dio_get_unit_order_raw
bool dio_get_unit_order_raw(struct data_in *din, struct unit_order *order) fc__attribute((nonnull(2)))
Definition dataio_raw.c:880
dio_set_put_conv_callback
void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun)
Definition dataio_raw.c:102
plocation_name
const char * plocation_name(const struct plocation *loc)
Definition dataio_raw.c:1097
dio_put_bool32_raw
void dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:393
dio_output_rewind
void dio_output_rewind(struct raw_data_out *dout)
Definition dataio_raw.c:193
dio_get_uint16_vec8_raw
bool dio_get_uint16_vec8_raw(struct data_in *din, int **values, int stop_value) fc__attribute((nonnull(2)))
Definition dataio_raw.c:967
dio_get_sint16_raw
bool dio_get_sint16_raw(struct data_in *din, int *dest) fc__attribute((nonnull(2)))
Definition dataio_raw.c:751
dio_put_sint8_raw
void dio_put_sint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:353
loc
struct tile * loc
Definition citydlg.c:220
type
GType type
Definition repodlgs.c:1312
name
const char * name
Definition inputfile.c:127
size
size_t size
Definition specvec.h:72
act_prob
Definition fc_types.h:1092
cm_parameter
Definition cm.h:40
data_in
Definition dataio_raw.h:30
data_in::src
const void * src
Definition dataio_raw.h:31
data_in::src_size
size_t src_size
Definition dataio_raw.h:32
data_in::current
size_t current
Definition dataio_raw.h:32
plocation
Definition dataio_raw.h:63
plocation::kind
enum plocation_kind kind
Definition dataio_raw.h:65
plocation::sub_location
struct plocation * sub_location
Definition dataio_raw.h:78
plocation::name
char * name
Definition dataio_raw.h:72
plocation::number
int number
Definition dataio_raw.h:69
raw_data_out
Definition dataio_raw.h:35
raw_data_out::too_short
bool too_short
Definition dataio_raw.h:38
raw_data_out::dest
void * dest
Definition dataio_raw.h:36
raw_data_out::used
size_t used
Definition dataio_raw.h:37
raw_data_out::dest_size
size_t dest_size
Definition dataio_raw.h:37
raw_data_out::current
size_t current
Definition dataio_raw.h:37
requirement
Definition requirements.h:80
unit_order
Definition unit.h:92
worklist
Definition worklist.h:28
support.h
fc__attribute
#define fc__attribute(x)
Definition support.h:89
bool
#define bool
Definition support.h:61