45 static bool get_conv(
char *dst,
size_t ndst,
const char *src,
size_t nsrc);
53 #if defined(FREECIV_TESTMATIC) && !defined(FIELD_RANGE_ASSERT)
54 #define FIELD_RANGE_ASSERT
57 #ifdef FIELD_RANGE_ASSERT
61 #define FIELD_RANGE_TEST(_test_, _action_, _format_, ...) \
62 fc_assert(!(_test_)); \
64 _action_ qCritical(_format_, ##__VA_ARGS__); \
67 #define FIELD_RANGE_TEST(_test_, _action_, _format_, ...) \
69 _action_ qCritical(_format_, ##__VA_ARGS__); \
85 static bool get_conv(
char *dst,
size_t ndst,
const char *src,
size_t nsrc)
90 if (ndst > 0 &&
len >= ndst) {
95 memcpy(dst, src,
len);
147 dout->
dest = destination;
235 "Trying to put %d into 8 bits; "
236 "it will result %d at receiving side.",
250 uint16_t x = qToBigEndian(uint16_t(value));
254 "Trying to put %d into 16 bits; "
255 "it will result %d at receiving side.",
256 value, (
int) qFromBigEndian(x));
269 uint32_t x = qToBigEndian(uint32_t(value));
273 "Trying to put %d into 32 bits; "
274 "it will result %d at receiving side.",
275 value, (
int) qFromBigEndian(x));
336 if (
sizeof(
int) == 4) {
349 ,
"Trying to put a non-boolean: %d", (int) value);
360 ,
"Trying to put a non-boolean: %d", (int) value);
372 uint32_t v = value * float_factor;
375 fabsf((
float) v / float_factor - value) > 1.1 / float_factor, ,
376 "Trying to put %f with factor %d in 32 bits; "
377 "it will result %f at receiving side, having error of %f units.",
378 value, float_factor, (
float) v / float_factor,
379 fabsf((
float) v / float_factor - value) * float_factor);
391 int32_t v = value * float_factor;
394 fabsf((
float) v / float_factor - value) > 1.1 / float_factor, ,
395 "Trying to put %f with factor %d in 32 bits; "
396 "it will result %f at receiving side, having error of %f units.",
397 value, float_factor, (
float) v / float_factor,
398 fabsf((
float) v / float_factor - value) * float_factor);
441 for (i = 0; i <
O_LAST; i++) {
450 for (i = 0; i <
O_LAST; i++) {
481 for (i = 0; i < length; i++) {
499 log_packet(
"Packet too short to read 1 byte");
520 log_packet(
"Packet too short to read 2 bytes");
526 *dest = qFromBigEndian(x);
541 log_packet(
"Packet too short to read 4 bytes");
547 *dest = qFromBigEndian(x);
589 if (ival != 0 && ival != 1) {
609 if (ival != 0 && ival != 1) {
630 *dest =
static_cast<float>(ival) / float_factor;
646 *dest =
static_cast<float>(ival) / float_factor;
697 if (
sizeof(
int) != 4) {
698 if (tmp > 0x7fffffff) {
726 size_t max_dest_size)
729 size_t offset, remaining;
742 for (offset = 0; offset < remaining && c[offset] !=
'\0'; offset++) {
746 if (offset >= remaining) {
768 for (i = 0; i <
O_LAST; i++) {
783 for (i = 0; i <
O_LAST; i++) {
804 int iorder, iactivity, idir;
816 order->
activity = unit_activity(iactivity);
817 order->
dir = direction8(idir);
837 for (i = 0; i < length; i++) {
893 bool survives, present, quiet;
905 if (preq->
source.
kind == universals_n_invalid()) {
907 qWarning() <<
"The server sent an invalid or unknown requirement.";
921 bool survives, present, quiet;
void dio_put_cm_parameter_raw(struct raw_data_out *dout, const struct cm_parameter *param)
Insert cm_parameter struct.
void dio_put_action_probability_raw(struct raw_data_out *dout, const struct act_prob *aprob)
Serialize an action probability.
void dio_put_unit_order_raw(struct raw_data_out *dout, const struct unit_order *order)
Insert the given unit_order struct/.
bool dio_get_requirement_raw(struct data_in *din, struct requirement *preq)
De-serialize a requirement.
bool dio_get_sint8_raw(struct data_in *din, int *dest)
Take value from 8 bits.
static bool enough_space(struct raw_data_out *dout, size_t size)
Returns TRUE iff the output has size bytes available.
void dio_put_ufloat_raw(struct raw_data_out *dout, float value, int float_factor)
Insert a float number, which is multiplied by 'float_factor' before being encoded into an uint32.
bool dio_get_worklist_raw(struct data_in *din, struct worklist *pwl)
Take worklist item count and then kind and number for each item, and put them to provided worklist.
bool dio_get_action_probability_raw(struct data_in *din, struct act_prob *aprob)
De-serialize an action probability.
void dio_put_bool8_raw(struct raw_data_out *dout, bool value)
Insert value 0 or 1 using 8 bits.
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Initializes the output to the given output buffer and the given buffer size.
void dio_put_uint16_raw(struct raw_data_out *dout, int value)
Insert value using 16 bits.
void dio_put_sfloat_raw(struct raw_data_out *dout, float value, int float_factor)
Insert a float number, which is multiplied by 'float_factor' before being encoded into a sint32.
void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun)
Sets string conversion callback to use when getting text.
bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src, size_t nsrc)
Call the get_conv callback.
bool dio_get_sfloat_raw(struct data_in *din, float *dest, int float_factor)
Get a signed float number, which have been multiplied by 'float_factor' and encoded into a sint32 by ...
size_t dio_input_remaining(struct data_in *din)
Return the number of unread bytes.
void dio_put_uint8_raw(struct raw_data_out *dout, int value)
Insert value using 8 bits.
void dio_put_sint16_raw(struct raw_data_out *dout, int value)
Insert value using 16 bits.
bool dio_get_uint32_raw(struct data_in *din, int *dest)
Receive uint32 value to dest.
bool dio_get_sint16_raw(struct data_in *din, int *dest)
Take value from 16 bits.
bool dio_get_unit_order_raw(struct data_in *din, struct unit_order *order)
Take unit_order struct and put it in the provided orders.
bool dio_get_sint32_raw(struct data_in *din, int *dest)
Take value from 32 bits.
void dio_put_sint32_raw(struct raw_data_out *dout, int value)
Insert value using 32 bits.
bool dio_get_cm_parameter_raw(struct data_in *din, struct cm_parameter *param)
Get city manager parameters.
void dio_input_rewind(struct data_in *din)
Rewinds the stream so that the get-functions start from the beginning.
void dio_put_uint32_raw(struct raw_data_out *dout, int value)
Insert value using 32 bits.
bool dio_get_uint16_raw(struct data_in *din, int *dest)
Receive uint16 value to dest.
bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size)
Take memory block directly.
void dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size)
Insert block directly from memory.
static bool get_conv(char *dst, size_t ndst, const char *src, size_t nsrc)
Returns FALSE if the destination isn't large enough or the source was bad.
bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest)
Receive value using 'size' bits to dest.
bool dio_get_bool32_raw(struct data_in *din, bool *dest)
Take boolean value from 32 bits.
bool dio_get_ufloat_raw(struct data_in *din, float *dest, int float_factor)
Get an unsigned float number, which have been multiplied by 'float_factor' and encoded into an uint32...
void dio_put_worklist_raw(struct raw_data_out *dout, const struct worklist *pwl)
Insert number of worklist items as 8 bit value and then insert 8 bit kind and 8 bit number for each w...
void dio_put_requirement_raw(struct raw_data_out *dout, const struct requirement *preq)
Serialize a requirement.
bool dio_get_uint8_raw(struct data_in *din, int *dest)
Receive uint8 value to dest.
static bool enough_data(struct data_in *din, size_t size)
Returns TRUE iff the input contains size unread bytes.
static DIO_GET_CONV_FUN get_conv_callback
bool dio_input_skip(struct data_in *din, size_t size)
Skips 'n' bytes.
size_t data_type_size(enum data_type type)
Return the size of the data_type in bytes.
void dio_put_type_raw(struct raw_data_out *dout, enum data_type type, int value)
Insert value using 'size' bits.
bool dio_get_bool8_raw(struct data_in *din, bool *dest)
Take boolean value from 8 bits.
void dio_put_string_raw(struct raw_data_out *dout, const char *value)
Insert nullptr-terminated string.
size_t dio_output_used(struct raw_data_out *dout)
Return the maximum number of bytes used.
void dio_input_init(struct data_in *din, const void *src, size_t src_size)
Initializes the input to the given input buffer and the given number of valid input bytes.
#define FIELD_RANGE_TEST(_test_, _action_, _format_,...)
static DIO_PUT_CONV_FUN put_conv_callback
void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun)
Sets string conversion callback to be used when putting text.
bool dio_get_string_raw(struct data_in *din, char *dest, size_t max_dest_size)
Take string.
void dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Insert value 0 or 1 using 32 bits.
void dio_output_rewind(struct raw_data_out *dout)
Rewinds the stream so that the put-functions start from the beginning.
void dio_put_sint8_raw(struct raw_data_out *dout, int value)
Insert value using 8 bits.
bool(* DIO_GET_CONV_FUN)(char *dst, size_t ndst, const char *src, size_t nsrc)
char *(* DIO_PUT_CONV_FUN)(const char *src, size_t *length)
#define fc_assert_msg(condition, message,...)
#define fc_assert(condition)
#define FC_STATIC_ASSERT(cond, tag)
void req_get_values(const struct requirement *req, int *type, int *range, bool *survives, bool *present, bool *quiet, int *value)
Return the value of a req as a serializable integer.
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
Set the values of a req from serializable integers.
struct universal universal_by_number(const enum universals_n kind, const int value)
Combine values into a universal structure.
int universal_number(const struct universal *source)
Return the universal number of the constituent.
#define ADD_TO_POINTER(p, n)
int minimal_surplus[O_LAST]
enum unit_activity activity
struct universal entries[MAX_LEN_WORKLIST]
void worklist_init(struct worklist *pwl)
Initialize a worklist to be empty.
bool worklist_append(struct worklist *pwl, const struct universal *prod)
Adds the id to the next available slot in the worklist.
int worklist_length(const struct worklist *pwl)
Returns the number of entries in the worklist.