Botcraft 1.21.10
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 if (debug_subscription_data_type_ <= DebugSubscriptionDataType::None || debug_subscription_data_type_ >= DebugSubscriptionDataType::NUM_DEBUG_SUBSCRIPTION_DATA_TYPES)
54 {
55 throw std::runtime_error("Unable to create debug subscription data with id: " + std::to_string(static_cast<int>(debug_subscription_data_type_)) + ".");
56 }
57
58 switch (debug_subscription_data_type_)
59 {
61 return std::make_shared<DebugSubscriptionDataEmpty>();
63 return std::make_shared<DebugSubscriptionDataBeeInfo>();
65 return std::make_shared<DebugSubscriptionDataBrainDump>();
67 return std::make_shared<DebugSubscriptionDataBreezeInfo>();
69 return std::make_shared<DebugSubscriptionDataGoalInfo>();
71 return std::make_shared<DebugSubscriptionDataPathInfo>();
73 return std::make_shared<DebugSubscriptionDataEntityBlockIntersection>();
75 return std::make_shared<DebugSubscriptionDataHiveInfo>();
77 return std::make_shared<DebugSubscriptionDataPoiInfo>();
79 return std::make_shared<DebugSubscriptionDataOrientation>();
81 return std::make_shared<DebugSubscriptionDataEmpty>();
83 return std::make_shared<DebugSubscriptionDataRaids>();
85 return std::make_shared<DebugSubscriptionDataStructures>();
87 return std::make_shared<DebugSubscriptionDataGameEventListenerInfo>();
89 return std::make_shared<DebugSubscriptionDataNeighbor>();
91 return std::make_shared<DebugSubscriptionDataGameEventInfo>();
92 default:
93 // Should never happen
94 throw std::runtime_error("Unable to create debug subscription data with id: " + std::to_string(static_cast<int>(debug_subscription_data_type_)) + ".");
95 break;
96 }
97
98 // Should never happen
99 throw std::runtime_error("Unable to create debug subscription data with id: " + std::to_string(static_cast<int>(debug_subscription_data_type_)) + ".");
100 return nullptr;
101 }
102 }
103
105 {
106 DataType = data_type_;
107 Data = DebugSubscriptionDataFactory(DataType);
108
109 return *this;
110 }
111
113 {
114 DataType = data_type_;
115 Data = std::nullopt;
116
117 return *this;
118 }
119
120 void DebugSubscriptionUpdate::ReadImpl(ReadIterator& iter, size_t& length)
121 {
122 DataType = ReadData<DebugSubscriptionDataType, VarInt>(iter, length);
123 const bool has_data = ReadData<bool>(iter, length);
124 if (has_data)
125 {
126 Data = DebugSubscriptionDataFactory(DataType);
127 Data.value()->Read(iter, length);
128 }
129 }
130
132 {
133 WriteData<DebugSubscriptionDataType, VarInt>(DataType, container);
134 WriteData<bool>(Data.has_value(), container);
135 if (Data.has_value() && Data.value() != nullptr)
136 {
137 Data.value()->Write(container);
138 }
139 }
140
142 {
143 Json::Value output;
144
145 output[std::string(field_name<DataType_index>)] = static_cast<int>(DataType);
146 if (Data.has_value())
147 {
148 output[std::string(field_name<Data_index>)] = Data == nullptr ? Json::Object() : Data.value()->Serialize();
149 }
150
151 return output;
152 }
153
154
156 {
157 DataType = data_type_;
158 Data = DebugSubscriptionDataFactory(DataType);
159
160 return *this;
161 }
162
163 void DebugSubscriptionEvent::ReadImpl(ReadIterator& iter, size_t& length)
164 {
165 DataType = ReadData<DebugSubscriptionDataType, VarInt>(iter, length);
166 Data = DebugSubscriptionDataFactory(DataType);
167 if (Data != nullptr)
168 {
169 Data->Read(iter, length);
170 }
171 }
172
174 {
175 WriteData<DebugSubscriptionDataType, VarInt>(DataType, container);
176 if (Data != nullptr)
177 {
178 Data->Write(container);
179 }
180 }
181
182 Json::Value DebugSubscriptionEvent::SerializeImpl() const
183 {
184 Json::Value output;
185
186 output[std::string(field_name<DataType_index>)] = static_cast<int>(DataType);
187 output[std::string(field_name<Data_index>)] = Data == nullptr ? Json::Object() : Data->Serialize();
188
189 return output;
190 }
191}
192#endif
#define DEFINE_NETWORK_TYPE(ClassName)
DebugSubscriptionEvent & SetDataType(const DebugSubscriptionDataType data_type_)
DebugSubscriptionUpdate & SetDataType(const DebugSubscriptionDataType data_type_)
DebugSubscriptionUpdate & SetDataTypeNoData(const DebugSubscriptionDataType data_type_)
virtual Json::Value SerializeImpl() const =0
virtual void WriteImpl(WriteContainer &container) const =0
virtual Json::Value Serialize() const
virtual void ReadImpl(ReadIterator &iter, size_t &length)=0
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator