generated from AfonsoCMSousa/CPP-Template
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#ifndef MAPPER_HPP
|
|
#define MAPPER_HPP
|
|
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
|
|
#include "parcer.h"
|
|
#include "server_structs.h"
|
|
|
|
// INFO: This is basically a identity mapper between raw byte buffer and structs defined in server_structs.h
|
|
class Mapper {
|
|
private:
|
|
const uint_least8_t *buffer;
|
|
size_t buffer_size;
|
|
size_t offset;
|
|
bool ok;
|
|
|
|
public:
|
|
Mapper(const uint_least8_t *buf, size_t buf_size);
|
|
|
|
uint8_t get_message_type();
|
|
bool is_ok() const { return ok; }
|
|
|
|
void parse_new_session(trackAtributes &track);
|
|
void parse_new_connection(carAtributes &car);
|
|
void parse_connection_closed(carAtributes &car);
|
|
void parse_car_update(carAtributes &car);
|
|
void parse_car_info(carAtributes &car);
|
|
void parse_lap_completed(uint8_t &car_id, uint32_t &lap_time, uint32_t &cuts);
|
|
void parse_collision_event(uint8_t &car1, uint8_t &car2, uint8_t &event_type);
|
|
void parse_chat(uint8_t &car_id, char *message, size_t max_len);
|
|
void parse_client_loaded(uint8_t &car_id);
|
|
|
|
void set_size(size_t size) { this->buffer_size = size; }
|
|
void update_buffer(const uint8_t *buf, size_t size) {
|
|
this->buffer = buf;
|
|
this->buffer_size = size;
|
|
reset();
|
|
}
|
|
private:
|
|
// INFO: Reset the offset to 1 because the first byte is message type
|
|
void reset() { offset = 1; ok = true; }
|
|
};
|
|
|
|
#endif // MAPPER_HPP
|