|
13 | 13 | class Buffer { |
14 | 14 | private: |
15 | 15 | std::vector<uint8_t> _data; |
16 | | - size_t _pos; |
| 16 | + size_t _pos; |
17 | 17 |
|
18 | 18 | public: |
| 19 | + // ============================================================ |
| 20 | + // ========== CONSTRUCTEURS ========== |
| 21 | + // ============================================================ |
19 | 22 | Buffer(); |
20 | 23 | explicit Buffer(const std::vector<uint8_t>& data); |
21 | 24 |
|
22 | | - int readVarInt(); |
23 | | - void writeVarInt(int value); |
24 | | - void writeInt(int32_t value); |
25 | | - void writeIdentifierArray(const std::vector<std::string>& ids); |
26 | | - void writeUInt(uint32_t value); |
27 | 25 |
|
| 26 | + // ============================================================ |
| 27 | + // ========== LECTURE ========== |
| 28 | + // ============================================================ |
| 29 | + uint8_t readByte(); |
| 30 | + bool readBool(); |
| 31 | + int32_t readInt(); |
| 32 | + uint16_t readUShort(); |
| 33 | + uint64_t readUInt64(); |
| 34 | + int32_t readVarInt(); |
| 35 | + int64_t readVarInt64(); |
28 | 36 | std::string readString(int maxLength); |
29 | | - std::string readString(); // Read string without max length limit |
30 | | - void writeString(const std::string& str); |
| 37 | + std::string readString(); |
| 38 | + int64_t readInt64(); |
31 | 39 |
|
32 | | - // Array reading methods |
33 | | - std::vector<std::string> readStringArray(); |
34 | | - std::vector<int> readVarIntArray(); |
35 | | - template <typename T> std::vector<T> readArray(std::function<T()> reader) { |
| 40 | + std::vector<std::string> readStringArray(); |
| 41 | + std::vector<int> readVarIntArray(); |
| 42 | + |
| 43 | + template <typename T> |
| 44 | + std::vector<T> readArray(std::function<T()> reader) { |
36 | 45 | int count = readVarInt(); |
37 | | - if (count < 0) { |
38 | | - throw std::runtime_error("Negative array length"); |
39 | | - } |
| 46 | + if (count < 0) throw std::runtime_error("Negative array length"); |
40 | 47 | std::vector<T> result; |
41 | 48 | result.reserve(count); |
42 | | - |
43 | | - for (int i = 0; i < count; ++i) { |
| 49 | + for (int i = 0; i < count; ++i) |
44 | 50 | result.push_back(reader()); |
45 | | - } |
46 | | - |
47 | 51 | return result; |
48 | 52 | } |
49 | 53 |
|
50 | | - // Boolean reading methods |
51 | | - bool readBool(); |
52 | 54 |
|
53 | | - std::vector<uint8_t>& getData(); |
54 | | - size_t remaining() const; |
55 | | - uint16_t readUShort(); |
56 | | - void writeUShort(uint16_t value); |
57 | | - uint64_t readUInt64(); |
58 | | - long readLong(); |
59 | | - int32_t readInt(); |
60 | | - void writeLong(long value); |
61 | | - uint8_t readByte(); |
62 | | - void writeByte(uint8_t byte); |
63 | | - void writeBytes(const std::string& data); |
64 | | - void writeBytes(const std::vector<uint8_t>& data); |
65 | | - void writeUUID(const UUID& uuid); |
| 55 | + // ============================================================ |
| 56 | + // ========== ÉCRITURE ========== |
| 57 | + // ============================================================ |
| 58 | + void writeByte(uint8_t byte); |
| 59 | + void writeBytes(const std::string& data); |
| 60 | + void writeBytes(const std::vector<uint8_t>& data); |
66 | 61 |
|
67 | | - void writeBool(bool value); |
68 | | - void writeNBT(const std::string& nbtData); |
69 | | - void writePosition(int32_t x, int32_t y, int32_t z); |
70 | | - void writeFloat(float value); |
71 | | - void writeDouble(double value); |
72 | | - void writeIdentifier(const std::string& id); |
73 | | - void writeVarLong(int64_t value); |
74 | | - int64_t readVarLong(); |
| 62 | + void writeBool(bool value); |
| 63 | + void writeInt(int32_t value); |
| 64 | + void writeUInt(uint32_t value); |
| 65 | + void writeUShort(uint16_t value); |
| 66 | + void writeInt64(int64_t value); |
| 67 | + void writeFloat(float value); |
| 68 | + void writeDouble(double value); |
| 69 | + |
| 70 | + void writeVarInt(int value); |
| 71 | + void writeVarInt64(int64_t value); |
75 | 72 |
|
76 | | - // Known Packs packet specific methods |
77 | | - struct KnownPack { |
78 | | - std::string nameSpace; |
79 | | - std::string id; |
80 | | - std::string version; |
81 | | - }; |
82 | | - std::vector<KnownPack> readKnownPacks(); |
83 | | - void writeKnownPacks(const std::vector<KnownPack>& packs); |
| 73 | + void writeString(const std::string& str); |
| 74 | + void writeUUID(const UUID& uuid); |
| 75 | + void writePosition(int32_t x, int32_t y, int32_t z); |
| 76 | + void writeIdentifierArray(const std::vector<std::string>& ids); |
| 77 | + void prependBytes(const std::string& data); |
| 78 | + void prependByte(uint8_t byte); |
| 79 | + void prependVarInt(int value); |
| 80 | + |
| 81 | + // ============================================================ |
| 82 | + // ========== UTILITAIRES ========== |
| 83 | + // ============================================================ |
| 84 | + std::vector<uint8_t>& getData(); |
| 85 | + size_t remaining() const; |
84 | 86 | }; |
85 | 87 |
|
86 | 88 | #endif |
0 commit comments