1142 def get_code_cmp(self, location: Location) -> str:
1143 if not self.size.constant:
1145differ = ({self.size.old} != {self.size.real});
1147""".format(self = self)
1153 inner_cmp = prefix(" ", self.elem.get_code_cmp(location.sub))
1155 int {location.index};
1157 for ({location.index} = 0; {location.index} < {self.size.real}; {location.index}++) {{
1164""".format(self = self, location = location, inner_cmp = inner_cmp)
1166 def _get_code_put_full(self, location: Location, inner_put: str) -> str:
1167 """Helper method. Generate put code without array-diff."""
1168 inner_put = prefix(" ", inner_put)
1171 int {location.index};
1173#ifdef FREECIV_JSON_CONNECTION
1174 /* Create the array. */
1175 e |= DIO_PUT(farray, &dout, &field_addr, {self.size.real});
1177 /* Enter the array. */
1178 field_addr.sub_location = plocation_elem_new(0);
1179#endif /* FREECIV_JSON_CONNECTION */
1181 for ({location.index} = 0; {location.index} < {self.size.real}; {location.index}++) {{
1182#ifdef FREECIV_JSON_CONNECTION
1183 /* Next array element. */
1184 field_addr.sub_location->number = {location.index};
1185#endif /* FREECIV_JSON_CONNECTION */
1189#ifdef FREECIV_JSON_CONNECTION
1191 FC_FREE(field_addr.sub_location);
1192#endif /* FREECIV_JSON_CONNECTION */
1194""".format(self = self, location = location, inner_put = inner_put)
1196 def _get_code_put_diff(self, location: Location, inner_put: str) -> str:
1197 """Helper method. Generate array-diff put code."""
1198 inner_put = prefix(" ", inner_put)
1199 inner_cmp = prefix(" ", self.elem.get_code_cmp(location.sub))
1202 int {location.index};
1204#ifdef FREECIV_JSON_CONNECTION
1205 size_t count_{location.index} = 0;
1207 /* Create the array. */
1208 e |= DIO_PUT(farray, &dout, &field_addr, 0);
1211 field_addr.sub_location = plocation_elem_new(0);
1212#endif /* FREECIV_JSON_CONNECTION */
1214 fc_assert({self.size.real} < MAX_UINT16);
1216 for ({location.index} = 0; {location.index} < {self.size.real}; {location.index}++) {{
1220#ifdef FREECIV_JSON_CONNECTION
1221 /* Append next diff array element. */
1222 field_addr.sub_location->number = -1;
1224 /* Create the diff array element. */
1225 e |= DIO_PUT(farray, &dout, &field_addr, 2);
1227 /* Enter diff array element (start at the index address). */
1228 field_addr.sub_location->number = count_{location.index}++;
1229 field_addr.sub_location->sub_location = plocation_elem_new(0);
1230#endif /* FREECIV_JSON_CONNECTION */
1231 e |= DIO_PUT(uint16, &dout, &field_addr, {location.index});
1233#ifdef FREECIV_JSON_CONNECTION
1234 /* Content address. */
1235 field_addr.sub_location->sub_location->number = 1;
1236#endif /* FREECIV_JSON_CONNECTION */
1239#ifdef FREECIV_JSON_CONNECTION
1240 /* Exit diff array element. */
1241 FC_FREE(field_addr.sub_location->sub_location);
1242#endif /* FREECIV_JSON_CONNECTION */
1245#ifdef FREECIV_JSON_CONNECTION
1246 /* Append diff array element. */
1247 field_addr.sub_location->number = -1;
1249 /* Create the terminating diff array element. */
1250 e |= DIO_PUT(farray, &dout, &field_addr, 1);
1252 /* Enter diff array element (start at the index address). */
1253 field_addr.sub_location->number = count_{location.index};
1254 field_addr.sub_location->sub_location = plocation_elem_new(0);
1255#endif /* FREECIV_JSON_CONNECTION */
1256 e |= DIO_PUT(uint16, &dout, &field_addr, MAX_UINT16);
1258#ifdef FREECIV_JSON_CONNECTION
1259 /* Exit diff array element. */
1260 FC_FREE(field_addr.sub_location->sub_location);
1263 FC_FREE(field_addr.sub_location);
1264#endif /* FREECIV_JSON_CONNECTION */
1266""".format(self = self, location = location, inner_cmp = inner_cmp, inner_put = inner_put)
1275 def _get_code_get_full(self, location: Location, inner_get: str) -> str:
1276 """Helper method. Generate get code without array-diff."""
1277 size_check = prefix(" ", self.size.receive_size_check(location.name))
1278 inner_get = prefix(" ", inner_get)
1281 int {location.index};
1283#ifdef FREECIV_JSON_CONNECTION
1285 field_addr.sub_location = plocation_elem_new(0);
1286#endif /* FREECIV_JSON_CONNECTION */
1289 for ({location.index} = 0; {location.index} < {self.size.real}; {location.index}++) {{
1290#ifdef FREECIV_JSON_CONNECTION
1291 field_addr.sub_location->number = {location.index};
1292#endif /* FREECIV_JSON_CONNECTION */
1296#ifdef FREECIV_JSON_CONNECTION
1298 FC_FREE(field_addr.sub_location);
1299#endif /* FREECIV_JSON_CONNECTION */
1301""".format(self = self, location = location, inner_get = inner_get, size_check = size_check)
1303 def _get_code_get_diff(self, location: Location, inner_get: str) -> str:
1304 """Helper method. Generate array-diff get code."""
1305 inner_get = prefix(" ", inner_get)
1308#ifdef FREECIV_JSON_CONNECTION
1312 field_addr.sub_location = plocation_elem_new(0);
1314 for (count = 0;; count++) {{
1315 int {location.index};
1317 field_addr.sub_location->number = count;
1319 /* Enter diff array element (start at the index address). */
1320 field_addr.sub_location->sub_location = plocation_elem_new(0);
1321#else /* FREECIV_JSON_CONNECTION */
1323 int {location.index};
1324#endif /* FREECIV_JSON_CONNECTION */
1326 if (!DIO_GET(uint16, &din, &field_addr, &{location.index})) {{
1327 RECEIVE_PACKET_FIELD_ERROR({location.name});
1329 if ({location.index} == MAX_UINT16) {{
1330#ifdef FREECIV_JSON_CONNECTION
1331 /* Exit diff array element. */
1332 FC_FREE(field_addr.sub_location->sub_location);
1334 /* Exit diff array. */
1335 FC_FREE(field_addr.sub_location);
1336#endif /* FREECIV_JSON_CONNECTION */
1340 if ({location.index} > {self.size.real}) {{
1341 RECEIVE_PACKET_FIELD_ERROR({location.name},
1342 ": unexpected value %d "
1343 "(> {self.size.real}) in array diff",
1346#ifdef FREECIV_JSON_CONNECTION
1347 /* Content address. */
1348 field_addr.sub_location->sub_location->number = 1;
1349#endif /* FREECIV_JSON_CONNECTION */
1353#ifdef FREECIV_JSON_CONNECTION
1354 /* Exit diff array element. */
1355 FC_FREE(field_addr.sub_location->sub_location);
1356#endif /* FREECIV_JSON_CONNECTION */
1359#ifdef FREECIV_JSON_CONNECTION
1361 FC_FREE(field_addr.sub_location);
1362#endif /* FREECIV_JSON_CONNECTION */
1364""".format(self = self, location = location, inner_get = inner_get)