Botcraft 26.3
Loading...
Searching...
No Matches
DebugSubscription.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
5
21
22namespace ProtocolCraft
23{
39
40 // Subtypes
48
49 namespace
50 {
51 std::shared_ptr<DebugSubscriptionData> DebugSubscriptionDataFactory(const DebugSubscriptionDataType debug_subscription_data_type_)
52 {
53 switch (debug_subscription_data_type_)
54 {
56 return std::make_shared<DebugSubscriptionDataEmpty>();
58 return std::make_shared<DebugSubscriptionDataBeeInfo>();
60 return std::make_shared<DebugSubscriptionDataBrainDump>();
62 return std::make_shared<DebugSubscriptionDataBreezeInfo>();
64 return std::make_shared<DebugSubscriptionDataGoalInfo>();
66 return std::make_shared<DebugSubscriptionDataPathInfo>();
68 return std::make_shared<DebugSubscriptionDataEntityBlockIntersection>();
70 return std::make_shared<DebugSubscriptionDataHiveInfo>();
72 return std::make_shared<DebugSubscriptionDataPoiInfo>();
74 return std::make_shared<DebugSubscriptionDataOrientation>();
76 return std::make_shared<DebugSubscriptionDataEmpty>();
78 return std::make_shared<DebugSubscriptionDataRaids>();
80 return std::make_shared<DebugSubscriptionDataStructures>();
82 return std::make_shared<DebugSubscriptionDataGameEventListenerInfo>();
84 return std::make_shared<DebugSubscriptionDataNeighbor>();
86 return std::make_shared<DebugSubscriptionDataGameEventInfo>();
87 default:
88 // Should never happen
89 throw std::runtime_error("Unable to create debug subscription data with id: " + std::to_string(static_cast<int>(debug_subscription_data_type_)) + ".");
90 return nullptr;
91 }
92
93 // Should never happen
94 return nullptr;
95 }
96 }
97
99 {
100 return DebugSubscriptionDataFactory(type);
101 }
102
104 {
105 Type = type;
106 Data = std::nullopt;
107
108 return *this;
109 }
110
111 void DebugSubscriptionUpdate::ReadImpl(ReadIterator& iter, size_t& length)
112 {
113 Type = ReadData<DebugSubscriptionDataType, VarInt>(iter, length);
114 const bool has_data = ReadData<bool>(iter, length);
115 if (has_data)
116 {
117 Data = DebugSubscriptionDataFactory(Type);
118 Data.value()->Read(iter, length);
119 }
120 }
121
123 {
124 WriteData<DebugSubscriptionDataType, VarInt>(Type, container);
125 WriteData<bool>(Data.has_value(), container);
126 if (Data.has_value() && Data.value() != nullptr)
127 {
128 Data.value()->Write(container);
129 }
130 }
131
133
134
136 {
137 return DebugSubscriptionDataFactory(type);
138 }
139
141}
142#endif
#define DEFINE_NETWORK_TYPE(ClassName)
#define DEFINE_SERIALIZE(ClassName)
static std::shared_ptr< DebugSubscriptionData > CreateDebugSubscriptionData(const DebugSubscriptionDataType type)
static std::shared_ptr< DebugSubscriptionData > CreateDebugSubscriptionData(const DebugSubscriptionDataType type)
DebugSubscriptionUpdate & SetDataTypeNoData(const DebugSubscriptionDataType type)
virtual void WriteImpl(WriteContainer &container) const =0
virtual void ReadImpl(ReadIterator &iter, size_t &length)=0
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator