R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
AutoMatchmaking.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** rtype
4** AutoMatchmaking.hpp - Request automatic matchmaking
5*/
6
7#pragma once
8
9#include <capnp/message.h>
10#include <capnp/serialize.h>
11#include "schemas/c2s_messages.capnp.h"
12
13#include <vector>
14
17 public:
18 bool enabled;
19
20 // Constructor
21 AutoMatchmaking(bool en = true) : enabled(en) {}
22
23 // Serialize to bytes
24 std::vector<uint8_t> serialize() const {
25 ::capnp::MallocMessageBuilder message;
26
27 auto msg = message.initRoot<::AutoMatchmaking>();
28 msg.setEnabled(enabled);
29
30 // Serialize
31 kj::VectorOutputStream stream;
32 capnp::writeMessage(stream, message);
33 auto array = stream.getArray();
34 return std::vector<uint8_t>(array.begin(), array.end());
35 }
36
37 // Deserialize from bytes
38 static AutoMatchmaking deserialize(const std::vector<uint8_t> &data) {
39 kj::ArrayPtr<const capnp::word> words(reinterpret_cast<const capnp::word *>(data.data()),
40 data.size() / sizeof(capnp::word));
41
42 capnp::FlatArrayMessageReader reader(words);
43
44 auto msg = reader.getRoot<::AutoMatchmaking>();
45
46 AutoMatchmaking result;
47 result.enabled = msg.getEnabled();
48 return result;
49 }
50 };
51} // namespace RType::Messages::C2S
std::vector< uint8_t > serialize() const
static AutoMatchmaking deserialize(const std::vector< uint8_t > &data)
Client-to-Server messages.