Feature #496 » 0003-json-protocol-allow-object-creation-in-packet-code.patch
| common/generate_packets.py | ||
|---|---|---|
|
{location.json_subloc}->number = -1;
|
||
|
/* Create the diff array element. */
|
||
|
e |= DIO_PUT(farray, &dout, &field_addr, 2);
|
||
|
e |= DIO_PUT(object, &dout, &field_addr);
|
||
|
/* Enter diff array element (start at the index address). */
|
||
|
{location.json_subloc}->number = count_{location.index}++;
|
||
|
{location.json_subloc}->sub_location = plocation_elem_new(0);
|
||
|
{location.json_subloc}->sub_location = plocation_field_new("index");
|
||
|
#endif /* FREECIV_JSON_CONNECTION */
|
||
|
/* Write the index */
|
||
| ... | ... | |
|
#ifdef FREECIV_JSON_CONNECTION
|
||
|
/* Content address. */
|
||
|
{location.json_subloc}->sub_location->number = 1;
|
||
|
{location.json_subloc}->sub_location->name = "data";
|
||
|
#endif /* FREECIV_JSON_CONNECTION */
|
||
|
{inner_put}\
|
||
| ... | ... | |
|
{location.json_subloc}->number = -1;
|
||
|
/* Create the terminating diff array element. */
|
||
|
e |= DIO_PUT(farray, &dout, &field_addr, 1);
|
||
|
e |= DIO_PUT(object, &dout, &field_addr);
|
||
|
/* Enter diff array element (start at the index address). */
|
||
|
{location.json_subloc}->number = count_{location.index};
|
||
|
{location.json_subloc}->sub_location = plocation_elem_new(0);
|
||
|
{location.json_subloc}->sub_location = plocation_field_new("index");
|
||
|
#endif /* FREECIV_JSON_CONNECTION */
|
||
|
/* Write the sentinel value */
|
||
| ... | ... | |
|
/* Enter array (start at initial element). */
|
||
|
{location.json_subloc} = plocation_elem_new(0);
|
||
|
/* Enter diff array element (start at the index address). */
|
||
|
{location.json_subloc}->sub_location = plocation_elem_new(0);
|
||
|
{location.json_subloc}->sub_location = plocation_field_new("index");
|
||
|
#endif /* FREECIV_JSON_CONNECTION */
|
||
|
while (TRUE) {{
|
||
| ... | ... | |
|
#ifdef FREECIV_JSON_CONNECTION
|
||
|
/* Content address. */
|
||
|
{location.json_subloc}->sub_location->number = 1;
|
||
|
{location.json_subloc}->sub_location->name = "data";
|
||
|
#endif /* FREECIV_JSON_CONNECTION */
|
||
|
{inner_get}\
|
||
| ... | ... | |
|
/* Move to the next diff array element. */
|
||
|
{location.json_subloc}->number++;
|
||
|
/* Back to the index address. */
|
||
|
{location.json_subloc}->sub_location->number = 0;
|
||
|
{location.json_subloc}->sub_location->name = "index";
|
||
|
#endif /* FREECIV_JSON_CONNECTION */
|
||
|
}}
|
||
| common/networking/dataio_json.c | ||
|---|---|---|
|
e = json_array_set_new(item, location->number, data);
|
||
|
}
|
||
|
} else {
|
||
|
// PTZ200718 handles last element get case...
|
||
|
// better here than all around put_array-diff algo ?
|
||
|
size_t n = (location->number == -1)
|
||
|
? (json_array_size(item) - 1)
|
||
|
: location->number;
|
||
|
json_t *sub_item = json_array_get(item, n);
|
||
|
if (json_is_array(sub_item)) {
|
||
|
e = plocation_write_data(sub_item,
|
||
|
location->sub_location, data);
|
||
|
} else {
|
||
|
log_error("ERROR:plocation_write_elem:array not found for sub location:"
|
||
|
"%s @[" SIZE_T_PRINTF "]",
|
||
|
json_dumps(item, JSON_DECODE_ANY), location->number);
|
||
|
}
|
||
|
e = plocation_write_data(json_array_get(item, n),
|
||
|
location->sub_location, data);
|
||
|
}
|
||
|
return e;
|
||
| ... | ... | |
|
return e;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Create an empty JSON object.
|
||
|
**************************************************************************/
|
||
|
int dio_put_object_json(struct json_data_out *dout,
|
||
|
const struct plocation *location)
|
||
|
{
|
||
|
int e = 0;
|
||
|
if (dout->json) {
|
||
|
e |= plocation_write_data(dout->json, location, json_object());
|
||
|
} else {
|
||
|
/* No caller needs this */
|
||
|
}
|
||
|
return e;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Insert uint32 value.
|
||
|
**************************************************************************/
|
||
| common/networking/dataio_json.h | ||
|---|---|---|
|
/* puts */
|
||
|
int dio_put_farray_json(struct json_data_out *dout,
|
||
|
const struct plocation *location, int size);
|
||
|
int dio_put_object_json(struct json_data_out *dout,
|
||
|
const struct plocation *location);
|
||
|
int dio_put_type_json(struct json_data_out *dout, enum data_type type,
|
||
|
const struct plocation *location,
|
||
- « Previous
- 1
- 2
- Next »