R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
RegisterResponse.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** r-type
4** File description:
5** RegisterResponse.hpp
6*/
7
8#pragma once
9
10#include <capnp/message.h>
11#include <capnp/serialize.h>
12#include <kj/array.h>
13#include <schemas/s2c_messages.capnp.h>
14#include <string>
15#include <vector>
16
17namespace RType {
18 namespace Messages {
19 namespace S2C {
20
26 public:
27 bool success;
28 std::string message;
29
30 RegisterResponse() = default;
31 RegisterResponse(bool s, const std::string &msg) : success(s), message(msg) {}
32
36 std::vector<uint8_t> serialize() const {
37 ::capnp::MallocMessageBuilder msgBuilder;
38 auto response = msgBuilder.initRoot<::RegisterResponse>();
39
40 response.setSuccess(success);
41 response.setMessage(message);
42
43 kj::Array<capnp::word> words = messageToFlatArray(msgBuilder);
44 auto bytes = words.asBytes();
45 return std::vector<uint8_t>(bytes.begin(), bytes.end());
46 }
47
51 static RegisterResponse deserialize(const std::vector<uint8_t> &data) {
52 kj::ArrayPtr<const capnp::word> words(reinterpret_cast<const capnp::word *>(data.data()),
53 data.size() / sizeof(capnp::word));
54
55 ::capnp::FlatArrayMessageReader msgReader(words);
56 auto response = msgReader.getRoot<::RegisterResponse>();
57
58 RegisterResponse result;
59 result.success = response.getSuccess();
60 result.message = response.getMessage().cStr();
61
62 return result;
63 }
64 };
65
66 } // namespace S2C
67 } // namespace Messages
68} // namespace RType
Server response to registration request.
std::vector< uint8_t > serialize() const
Serialize to Cap'n Proto binary format.
RegisterResponse(bool s, const std::string &msg)
static RegisterResponse deserialize(const std::vector< uint8_t > &data)
Deserialize from Cap'n Proto binary format.