Created a simple data serialization library, to serialize and deserialize the data to be sent

This commit is contained in:
2024-02-26 21:38:01 -05:00
parent 87b436aede
commit edfd70c3cc
2 changed files with 77 additions and 0 deletions

31
includes/serialization.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef _SERIALIZATION_H
#define _SERIALIZATION_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* Struct used to hold the data that will be sent between sockets */
typedef struct {
uint16_t pad_x;
uint16_t pad_y;
uint16_t ball_x;
uint16_t ball_y;
} 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);
/* 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