Freeciv21
Develop your civilization from humble roots to a global empire
dataio_raw.h File Reference
#include "support.h"
+ Include dependency graph for dataio_raw.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  data_in
 
struct  raw_data_out
 

Macros

#define DIO_BV_GET(pdin, bv)    dio_get_memory_raw((pdin), (bv).vec, sizeof((bv).vec))
 
#define DIO_GET(f, d, ...)   dio_get_##f##_raw(d, ##__VA_ARGS__)
 
#define DIO_BV_PUT(pdout, bv)    dio_put_memory_raw((pdout), (bv).vec, sizeof((bv).vec))
 
#define DIO_PUT(f, d, ...)   dio_put_##f##_raw(d, ##__VA_ARGS__)
 

Typedefs

typedef char *(* DIO_PUT_CONV_FUN) (const char *src, size_t *length)
 
typedef bool(* DIO_GET_CONV_FUN) (char *dst, size_t ndst, const char *src, size_t nsrc)
 

Enumerations

enum  data_type {
  DIOT_UINT8 , DIOT_UINT16 , DIOT_UINT32 , DIOT_SINT8 ,
  DIOT_SINT16 , DIOT_SINT32 , DIOT_LAST
}
 

Functions

void dio_set_put_conv_callback (DIO_PUT_CONV_FUN fun)
 Sets string conversion callback to be used when putting text. More...
 
void dio_set_get_conv_callback (DIO_GET_CONV_FUN fun)
 Sets string conversion callback to use when getting text. More...
 
bool dataio_get_conv_callback (char *dst, size_t ndst, const char *src, size_t nsrc)
 Call the get_conv callback. More...
 
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. More...
 
void dio_output_rewind (struct raw_data_out *dout)
 Rewinds the stream so that the put-functions start from the beginning. More...
 
size_t dio_output_used (struct raw_data_out *dout)
 Return the maximum number of bytes used. More...
 
void dio_input_init (struct data_in *dout, const void *src, size_t src_size)
 Initializes the input to the given input buffer and the given number of valid input bytes. More...
 
void dio_input_rewind (struct data_in *din)
 Rewinds the stream so that the get-functions start from the beginning. More...
 
size_t dio_input_remaining (struct data_in *din)
 Return the number of unread bytes. More...
 
bool dio_input_skip (struct data_in *din, size_t size)
 Skips 'n' bytes. More...
 
size_t data_type_size (enum data_type type)
 Return the size of the data_type in bytes. More...
 
bool dio_get_type_raw (struct data_in *din, enum data_type type, int *dest) fc__attribute((nonnull(3)))
 Receive value using 'size' bits to dest. More...
 
bool dio_get_uint8_raw (struct data_in *din, int *dest) fc__attribute((nonnull(2)))
 Receive uint8 value to dest. More...
 
bool dio_get_uint16_raw (struct data_in *din, int *dest) fc__attribute((nonnull(2)))
 Receive uint16 value to dest. More...
 
bool dio_get_uint32_raw (struct data_in *din, int *dest) fc__attribute((nonnull(2)))
 Receive uint32 value to dest. More...
 
bool dio_get_sint8_raw (struct data_in *din, int *dest) fc__attribute((nonnull(2)))
 Take value from 8 bits. More...
 
bool dio_get_sint16_raw (struct data_in *din, int *dest) fc__attribute((nonnull(2)))
 Take value from 16 bits. More...
 
bool dio_get_sint32_raw (struct data_in *din, int *dest) fc__attribute((nonnull(2)))
 Take value from 32 bits. More...
 
bool dio_get_bool8_raw (struct data_in *din, bool *dest) fc__attribute((nonnull(2)))
 Take boolean value from 8 bits. More...
 
bool dio_get_bool32_raw (struct data_in *din, bool *dest) fc__attribute((nonnull(2)))
 Take boolean value from 32 bits. More...
 
bool dio_get_ufloat_raw (struct data_in *din, float *dest, int float_factor) fc__attribute((nonnull(2)))
 Get an unsigned float number, which have been multiplied by 'float_factor' and encoded into an uint32 by dio_put_ufloat_raw(). More...
 
bool dio_get_sfloat_raw (struct data_in *din, float *dest, int float_factor) fc__attribute((nonnull(2)))
 Get a signed float number, which have been multiplied by 'float_factor' and encoded into a sint32 by dio_put_sfloat(). More...
 
bool dio_get_memory_raw (struct data_in *din, void *dest, size_t dest_size) fc__attribute((nonnull(2)))
 Take memory block directly. More...
 
bool dio_get_string_raw (struct data_in *din, char *dest, size_t max_dest_size) fc__attribute((nonnull(2)))
 Take string. More...
 
bool dio_get_cm_parameter_raw (struct data_in *din, struct cm_parameter *param) fc__attribute((nonnull(2)))
 Get city manager parameters. More...
 
bool dio_get_worklist_raw (struct data_in *din, struct worklist *pwl) fc__attribute((nonnull(2)))
 Take worklist item count and then kind and number for each item, and put them to provided worklist. More...
 
bool dio_get_unit_order_raw (struct data_in *din, struct unit_order *order) fc__attribute((nonnull(2)))
 Take unit_order struct and put it in the provided orders. More...
 
bool dio_get_requirement_raw (struct data_in *din, struct requirement *preq) fc__attribute((nonnull(2)))
 De-serialize a requirement. More...
 
bool dio_get_action_probability_raw (struct data_in *din, struct act_prob *aprob) fc__attribute((nonnull(2)))
 De-serialize an action probability. More...
 
void dio_put_type_raw (struct raw_data_out *dout, enum data_type type, int value)
 Insert value using 'size' bits. More...
 
void dio_put_uint8_raw (struct raw_data_out *dout, int value)
 Insert value using 8 bits. More...
 
void dio_put_uint16_raw (struct raw_data_out *dout, int value)
 Insert value using 16 bits. More...
 
void dio_put_uint32_raw (struct raw_data_out *dout, int value)
 Insert value using 32 bits. More...
 
void dio_put_sint8_raw (struct raw_data_out *dout, int value)
 Insert value using 8 bits. More...
 
void dio_put_sint16_raw (struct raw_data_out *dout, int value)
 Insert value using 16 bits. More...
 
void dio_put_sint32_raw (struct raw_data_out *dout, int value)
 Insert value using 32 bits. More...
 
void dio_put_bool8_raw (struct raw_data_out *dout, bool value)
 Insert value 0 or 1 using 8 bits. More...
 
void dio_put_bool32_raw (struct raw_data_out *dout, bool value)
 Insert value 0 or 1 using 32 bits. More...
 
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. More...
 
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. More...
 
void dio_put_memory_raw (struct raw_data_out *dout, const void *value, size_t size)
 Insert block directly from memory. More...
 
void dio_put_string_raw (struct raw_data_out *dout, const char *value)
 Insert nullptr-terminated string. More...
 
void dio_put_city_map_raw (struct raw_data_out *dout, const char *value)
 
void dio_put_cm_parameter_raw (struct raw_data_out *dout, const struct cm_parameter *param)
 Insert cm_parameter struct. More...
 
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 worklist item. More...
 
void dio_put_unit_order_raw (struct raw_data_out *dout, const struct unit_order *order)
 Insert the given unit_order struct/. More...
 
void dio_put_requirement_raw (struct raw_data_out *dout, const struct requirement *preq)
 Serialize a requirement. More...
 
void dio_put_action_probability_raw (struct raw_data_out *dout, const struct act_prob *aprob)
 Serialize an action probability. More...
 

Macro Definition Documentation

◆ DIO_BV_GET

#define DIO_BV_GET (   pdin,
  bv 
)     dio_get_memory_raw((pdin), (bv).vec, sizeof((bv).vec))

Definition at line 116 of file dataio_raw.h.

◆ DIO_BV_PUT

#define DIO_BV_PUT (   pdout,
  bv 
)     dio_put_memory_raw((pdout), (bv).vec, sizeof((bv).vec))

Definition at line 156 of file dataio_raw.h.

◆ DIO_GET

#define DIO_GET (   f,
  d,
  ... 
)    dio_get_##f##_raw(d, ##__VA_ARGS__)

Definition at line 119 of file dataio_raw.h.

◆ DIO_PUT

#define DIO_PUT (   f,
  d,
  ... 
)    dio_put_##f##_raw(d, ##__VA_ARGS__)

Definition at line 159 of file dataio_raw.h.

Typedef Documentation

◆ DIO_GET_CONV_FUN

typedef bool(* DIO_GET_CONV_FUN) (char *dst, size_t ndst, const char *src, size_t nsrc)

Definition at line 52 of file dataio_raw.h.

◆ DIO_PUT_CONV_FUN

typedef char*(* DIO_PUT_CONV_FUN) (const char *src, size_t *length)

Definition at line 49 of file dataio_raw.h.

Enumeration Type Documentation

◆ data_type

enum data_type
Enumerator
DIOT_UINT8 
DIOT_UINT16 
DIOT_UINT32 
DIOT_SINT8 
DIOT_SINT16 
DIOT_SINT32 
DIOT_LAST 

Definition at line 37 of file dataio_raw.h.

Function Documentation

◆ data_type_size()

size_t data_type_size ( enum data_type  type)

Return the size of the data_type in bytes.

Definition at line 193 of file dataio_raw.cpp.

Referenced by conn_compression_flush(), and get_packet_from_connection_raw().

◆ dataio_get_conv_callback()

bool dataio_get_conv_callback ( char *  dst,
size_t  ndst,
const char *  src,
size_t  nsrc 
)

Call the get_conv callback.

Definition at line 112 of file dataio_raw.cpp.

◆ dio_get_action_probability_raw()

bool dio_get_action_probability_raw ( struct data_in din,
struct act_prob aprob 
)

De-serialize an action probability.

Definition at line 861 of file dataio_raw.cpp.

◆ dio_get_bool32_raw()

bool dio_get_bool32_raw ( struct data_in din,
bool *  dest 
)

Take boolean value from 32 bits.

Definition at line 601 of file dataio_raw.cpp.

◆ dio_get_bool8_raw()

bool dio_get_bool8_raw ( struct data_in din,
bool *  dest 
)

Take boolean value from 8 bits.

Definition at line 581 of file dataio_raw.cpp.

Referenced by dio_get_cm_parameter_raw(), dio_get_requirement_raw(), and cma_yoloswag::get_parameter().

◆ dio_get_cm_parameter_raw()

bool dio_get_cm_parameter_raw ( struct data_in din,
struct cm_parameter param 
)

Get city manager parameters.

Definition at line 763 of file dataio_raw.cpp.

◆ dio_get_memory_raw()

bool dio_get_memory_raw ( struct data_in din,
void *  dest,
size_t  dest_size 
)

Take memory block directly.

Definition at line 710 of file dataio_raw.cpp.

Referenced by attribute_get().

◆ dio_get_requirement_raw()

bool dio_get_requirement_raw ( struct data_in din,
struct requirement preq 
)

De-serialize a requirement.

Definition at line 890 of file dataio_raw.cpp.

◆ dio_get_sfloat_raw()

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 dio_put_sfloat().

Definition at line 638 of file dataio_raw.cpp.

◆ dio_get_sint16_raw()

bool dio_get_sint16_raw ( struct data_in din,
int *  dest 
)

Take value from 16 bits.

Definition at line 671 of file dataio_raw.cpp.

Referenced by dio_get_cm_parameter_raw(), dio_get_type_raw(), dio_get_unit_order_raw(), and cma_yoloswag::get_parameter().

◆ dio_get_sint32_raw()

bool dio_get_sint32_raw ( struct data_in din,
int *  dest 
)

Take value from 32 bits.

Definition at line 689 of file dataio_raw.cpp.

Referenced by dio_get_requirement_raw(), dio_get_sfloat_raw(), dio_get_type_raw(), and dio_get_unit_order_raw().

◆ dio_get_sint8_raw()

bool dio_get_sint8_raw ( struct data_in din,
int *  dest 
)

Take value from 8 bits.

Definition at line 653 of file dataio_raw.cpp.

Referenced by dio_get_type_raw(), and dio_get_unit_order_raw().

◆ dio_get_string_raw()

bool dio_get_string_raw ( struct data_in din,
char *  dest,
size_t  max_dest_size 
)

Take string.

Conversion callback is used.

Definition at line 725 of file dataio_raw.cpp.

◆ dio_get_type_raw()

bool dio_get_type_raw ( struct data_in din,
enum data_type  type,
int *  dest 
)

Receive value using 'size' bits to dest.

Definition at line 555 of file dataio_raw.cpp.

Referenced by get_packet_from_connection_raw(), and packet_check().

◆ dio_get_ufloat_raw()

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 by dio_put_ufloat_raw().

Definition at line 622 of file dataio_raw.cpp.

◆ dio_get_uint16_raw()

bool dio_get_uint16_raw ( struct data_in din,
int *  dest 
)

Receive uint16 value to dest.

Definition at line 513 of file dataio_raw.cpp.

Referenced by dio_get_cm_parameter_raw(), dio_get_sint16_raw(), dio_get_type_raw(), and remove_packet_from_buffer().

◆ dio_get_uint32_raw()

bool dio_get_uint32_raw ( struct data_in din,
int *  dest 
)

◆ dio_get_uint8_raw()

◆ dio_get_unit_order_raw()

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.

Definition at line 801 of file dataio_raw.cpp.

◆ dio_get_worklist_raw()

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.

Definition at line 826 of file dataio_raw.cpp.

◆ dio_input_init()

void dio_input_init ( struct data_in dout,
const void *  src,
size_t  src_size 
)

Initializes the input to the given input buffer and the given number of valid input bytes.

Definition at line 169 of file dataio_raw.cpp.

Referenced by attribute_get(), get_lanserver_announcement(), get_packet_from_connection_raw(), cma_yoloswag::get_parameter(), and remove_packet_from_buffer().

◆ dio_input_remaining()

size_t dio_input_remaining ( struct data_in din)

Return the number of unread bytes.

Definition at line 185 of file dataio_raw.cpp.

Referenced by dio_get_string_raw(), enough_data(), get_packet_from_connection_raw(), and packet_check().

◆ dio_input_rewind()

void dio_input_rewind ( struct data_in din)

Rewinds the stream so that the get-functions start from the beginning.

Definition at line 180 of file dataio_raw.cpp.

Referenced by packet_check().

◆ dio_input_skip()

bool dio_input_skip ( struct data_in din,
size_t  size 
)

Skips 'n' bytes.

Definition at line 216 of file dataio_raw.cpp.

◆ dio_output_init()

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.

Definition at line 144 of file dataio_raw.cpp.

Referenced by attribute_set(), fcUdpScan::begin_scan(), conn_compression_flush(), send_lanserver_response(), server_packet_input(), and cma_yoloswag::set_parameter().

◆ dio_output_rewind()

void dio_output_rewind ( struct raw_data_out dout)

Rewinds the stream so that the put-functions start from the beginning.

Definition at line 163 of file dataio_raw.cpp.

Referenced by server_packet_input().

◆ dio_output_used()

size_t dio_output_used ( struct raw_data_out dout)

Return the maximum number of bytes used.

Definition at line 157 of file dataio_raw.cpp.

Referenced by fcUdpScan::begin_scan(), send_lanserver_response(), server_packet_input(), and cma_yoloswag::set_parameter().

◆ dio_put_action_probability_raw()

void dio_put_action_probability_raw ( struct raw_data_out dout,
const struct act_prob aprob 
)

Serialize an action probability.

Definition at line 880 of file dataio_raw.cpp.

◆ dio_put_bool32_raw()

void dio_put_bool32_raw ( struct raw_data_out dout,
bool  value 
)

Insert value 0 or 1 using 32 bits.

Definition at line 357 of file dataio_raw.cpp.

Referenced by server_packet_input().

◆ dio_put_bool8_raw()

void dio_put_bool8_raw ( struct raw_data_out dout,
bool  value 
)

Insert value 0 or 1 using 8 bits.

Definition at line 346 of file dataio_raw.cpp.

Referenced by dio_put_cm_parameter_raw(), dio_put_requirement_raw(), and cma_yoloswag::set_parameter().

◆ dio_put_city_map_raw()

void dio_put_city_map_raw ( struct raw_data_out dout,
const char *  value 
)

◆ dio_put_cm_parameter_raw()

void dio_put_cm_parameter_raw ( struct raw_data_out dout,
const struct cm_parameter param 
)

Insert cm_parameter struct.

Definition at line 436 of file dataio_raw.cpp.

◆ dio_put_memory_raw()

void dio_put_memory_raw ( struct raw_data_out dout,
const void *  value,
size_t  size 
)

Insert block directly from memory.

Definition at line 406 of file dataio_raw.cpp.

Referenced by attribute_set(), and dio_put_string_raw().

◆ dio_put_requirement_raw()

void dio_put_requirement_raw ( struct raw_data_out dout,
const struct requirement preq 
)

Serialize a requirement.

Definition at line 917 of file dataio_raw.cpp.

◆ dio_put_sfloat_raw()

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.

Definition at line 388 of file dataio_raw.cpp.

◆ dio_put_sint16_raw()

void dio_put_sint16_raw ( struct raw_data_out dout,
int  value 
)

Insert value using 16 bits.

May overflow.

Definition at line 326 of file dataio_raw.cpp.

Referenced by dio_put_cm_parameter_raw(), dio_put_type_raw(), dio_put_unit_order_raw(), and cma_yoloswag::set_parameter().

◆ dio_put_sint32_raw()

void dio_put_sint32_raw ( struct raw_data_out dout,
int  value 
)

Insert value using 32 bits.

May overflow.

Definition at line 334 of file dataio_raw.cpp.

Referenced by dio_put_requirement_raw(), dio_put_sfloat_raw(), dio_put_type_raw(), and dio_put_unit_order_raw().

◆ dio_put_sint8_raw()

void dio_put_sint8_raw ( struct raw_data_out dout,
int  value 
)

Insert value using 8 bits.

May overflow.

Definition at line 318 of file dataio_raw.cpp.

Referenced by dio_put_type_raw(), and dio_put_unit_order_raw().

◆ dio_put_string_raw()

void dio_put_string_raw ( struct raw_data_out dout,
const char *  value 
)

Insert nullptr-terminated string.

Conversion callback is used if set.

Definition at line 418 of file dataio_raw.cpp.

Referenced by send_lanserver_response(), and server_packet_input().

◆ dio_put_type_raw()

void dio_put_type_raw ( struct raw_data_out dout,
enum data_type  type,
int  value 
)

Insert value using 'size' bits.

May overflow.

Definition at line 286 of file dataio_raw.cpp.

◆ dio_put_ufloat_raw()

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.

Definition at line 369 of file dataio_raw.cpp.

◆ dio_put_uint16_raw()

void dio_put_uint16_raw ( struct raw_data_out dout,
int  value 
)

Insert value using 16 bits.

May overflow.

Definition at line 248 of file dataio_raw.cpp.

Referenced by conn_compression_flush(), dio_put_cm_parameter_raw(), dio_put_sint16_raw(), dio_put_type_raw(), and server_packet_input().

◆ dio_put_uint32_raw()

void dio_put_uint32_raw ( struct raw_data_out dout,
int  value 
)

Insert value using 32 bits.

May overflow.

Definition at line 267 of file dataio_raw.cpp.

Referenced by attribute_set(), conn_compression_flush(), dio_put_bool32_raw(), dio_put_sint32_raw(), dio_put_type_raw(), and dio_put_ufloat_raw().

◆ dio_put_uint8_raw()

◆ dio_put_unit_order_raw()

void dio_put_unit_order_raw ( struct raw_data_out dout,
const struct unit_order order 
)

Insert the given unit_order struct/.

Definition at line 460 of file dataio_raw.cpp.

◆ dio_put_worklist_raw()

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 worklist item.

Definition at line 475 of file dataio_raw.cpp.

◆ dio_set_get_conv_callback()

void dio_set_get_conv_callback ( DIO_GET_CONV_FUN  fun)

Sets string conversion callback to use when getting text.

Definition at line 104 of file dataio_raw.cpp.

Referenced by charsets_init().

◆ dio_set_put_conv_callback()

void dio_set_put_conv_callback ( DIO_PUT_CONV_FUN  fun)

Sets string conversion callback to be used when putting text.

Definition at line 76 of file dataio_raw.cpp.

Referenced by charsets_init().