Botcraft 26.3
Loading...
Searching...
No Matches
OptionalVarInt.hpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 776 /* > 26.2 */
2#pragma once
4
5#include <optional>
6
7namespace ProtocolCraft
8{
10 {
11 private:
12 std::optional<int> ReadValue(ReadIterator& iter, size_t& length) const
13 {
14 const int i = ReadData<VarInt>(iter, length);
15 if (i == 0)
16 {
17 return std::nullopt;
18 }
19 return i - 1;
20 }
21
22 void WriteValue(const std::optional<int>& i, WriteContainer& container) const
23 {
24 if (i.has_value())
25 {
26 WriteData<VarInt>(i.value() + 1, container);
27 }
28 else
29 {
30 WriteData<VarInt>(0, container);
31 }
32 }
33
35
37 };
38}
39#endif
std::optional< int > ReadValue(ReadIterator &iter, size_t &length) const
SERIALIZED_FIELD(Value, Internal::CustomType< std::optional< int >, &OptionalVarInt::ReadValue, &OptionalVarInt::WriteValue, nullptr >)
void WriteValue(const std::optional< int > &i, WriteContainer &container) const
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator