Feature #466 ยป 0002-Add-dataio-arraylen-type.patch
| common/networking/dataio_json.c | ||
|---|---|---|
|
return TRUE;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Receive array length value to dest with json. In json mode, this will
|
||
|
simply read the length of the array at that location.
|
||
|
**************************************************************************/
|
||
|
bool dio_get_arraylen_json(struct connection *pc, struct data_in *din,
|
||
|
const struct plocation *location, int *dest)
|
||
|
{
|
||
|
if (pc->json_mode) {
|
||
|
const json_t *arr = plocation_read_data(pc->json_packet, location);
|
||
|
if (!json_is_array(arr)) {
|
||
|
log_packet("Not an array");
|
||
|
return FALSE;
|
||
|
}
|
||
|
*dest = json_array_size(arr);
|
||
|
} else {
|
||
|
return dio_get_arraylen_raw(din, dest);
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Receive vector of 8 bit values, terminated by stop_value.
|
||
|
**************************************************************************/
|
||
| ... | ... | |
|
return e;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Insert array length. In json mode, this will create an array at that
|
||
|
location.
|
||
|
**************************************************************************/
|
||
|
int dio_put_arraylen_json(struct json_data_out *dout,
|
||
|
const struct plocation *location, int size)
|
||
|
{
|
||
|
int e;
|
||
|
if (dout->json) {
|
||
|
e = dio_put_farray_json(dout, location, size);
|
||
|
} else {
|
||
|
e = dio_put_arraylen_raw(&dout->raw, size);
|
||
|
}
|
||
|
return e;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Insert vector of uint8 values, terminated by stop_value.
|
||
|
**************************************************************************/
|
||
| common/networking/dataio_json.h | ||
|---|---|---|
|
struct act_prob *prob)
|
||
|
fc__attribute((nonnull (4)));
|
||
|
bool dio_get_arraylen_json(struct connection *pc, struct data_in *din,
|
||
|
const struct plocation *location, int *dest)
|
||
|
fc__attribute((nonnull (4)));
|
||
|
bool dio_get_uint8_vec8_json(struct connection *pc, struct data_in *din,
|
||
|
const struct plocation *location,
|
||
|
int **values, int stop_value)
|
||
| ... | ... | |
|
const struct plocation *location,
|
||
|
const struct act_prob *prob);
|
||
|
int dio_put_arraylen_json(struct json_data_out *dout,
|
||
|
const struct plocation *location, int size);
|
||
|
int dio_put_uint8_vec8_json(struct json_data_out *dout,
|
||
|
const struct plocation *location,
|
||
|
int *values, int stop_value);
|
||
| common/networking/dataio_raw.h | ||
|---|---|---|
|
#define dio_get_estring_raw dio_get_string_raw
|
||
|
#define dio_put_estring_raw dio_put_string_raw
|
||
|
/* In the binary protocol, just encode the array lengths. */
|
||
|
#define dio_get_arraylen_raw dio_get_uint16_raw
|
||
|
#define dio_put_arraylen_raw dio_put_uint16_raw
|
||
|
#ifndef FREECIV_JSON_CONNECTION
|
||
|
/* Should be a function but we need some macro magic. */
|
||