//flags for identify the structs
#define STRUCT_TYPE_A (1<<0)
#define STRUCT_TYPE_B (1<<1)
#define STRUCT_TYPE_C (1<<2)
//our test struct
typedef struct TEST_STRUCT {
char flags; //importent: the flag-char have to be the first property
//char = 1Byte -> can store 8flags
var value; //content of the struct
char msg[25];
} TEST_STRUCT;
//example for a sending function
void sendingStruct(var reciever, var type, var value, char msg) {
TEST_STRUCT *newPacket = malloc(sizeof(TEST_STRUCT));
newPacket.flags = NULL;
newPacket.flags |= type;
newPacket.value = value;
newPacket.msg = msg;
send_struct_id(reciever,newPacket,sizeof(TEST_STRUCT));
wait(-dplay_entrate/16);
free(newPacket);
}
//example for a recieving function
on_server_event(void *clientBuf, var clientID) {
if(event_type == EVENT_DATA) {
char *tempBuf = clientBuf;
//now tempBuf[0] points to the first byte of the
//incomming struct - its the flag-property
//so with this you can check the type
if((tempBuf[0] & STRUCT_TYPE_A) == STRUCT_TYPE_A) {
error("Type A");
}
if((tempBuf[0] & STRUCT_TYPE_B) == STRUCT_TYPE_B) {
error("Type B");
}
if((tempBuf[0] & STRUCT_TYPE_C) == STRUCT_TYPE_C) {
error("Type C");
}
}
}
//test main
void main() {
//if it's a client
if(connection == CONNECT_CLIENT) {
//after connecting
while (dplay_status < 2) { wait(1); }
//sending a test
sendingStruct(NULL, STRUCT_TYPE_A, 3, "Test!");
}
return;
}