You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
998 B
C
34 lines
998 B
C
#ifndef _SERIALIZATION_H
|
|
#define _SERIALIZATION_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/* Struct used to hold the data that will be sent between sockets */
|
|
typedef struct {
|
|
uint16_t pad_x; // X-coordinate of sending paddle
|
|
uint16_t pad_y; // Y-coordinate of sending paddle
|
|
uint16_t ball_x; // X-coordinate of ball (only the server fills this in)
|
|
uint16_t ball_y; // Y-coordinate of ball (only the server fills this in)
|
|
bool should_quit; // Flag to indicate whether game should be quit or not
|
|
} Serial_Data;
|
|
|
|
/* Create a Serial_Data struct from float values */
|
|
Serial_Data Serial_create_data(float pad_x, float pad_y, float ball_x, float ball_y, bool should_quit);
|
|
|
|
/* Serialize a struct into a byte array, that can be sent through a socket */
|
|
uint8_t* Serial_serialize(Serial_Data data);
|
|
|
|
/* Deserialize a byte array into a struct, and return the struct */
|
|
Serial_Data Serial_deserialize(uint8_t* serialized);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|