Botcraft 1.21.4
Loading...
Searching...
No Matches
DNSQuestion.hpp
Go to the documentation of this file.
1#pragma once
2
4
5using namespace ProtocolCraft;
6
7namespace Botcraft
8{
9 class DNSQuestion : public NetworkType
10 {
11 public:
12 const std::vector<std::string>& GetNameLabels() const
13 {
14 return name_labels;
15 }
16
17 const unsigned short GetTypeCode() const
18 {
19 return type_code;
20 }
21
22 const unsigned short GetClassCode() const
23 {
24 return class_code;
25 }
26
27
28 void SetNameLabels(const std::vector<std::string>& name_labels_)
29 {
30 name_labels = name_labels_;
31 }
32
33 void SetTypeCode(const unsigned short type_code_)
34 {
35 type_code = type_code_;
36 }
37
38 void SetClassCode(const unsigned short class_code_)
39 {
40 class_code = class_code_;
41 }
42
43 protected:
44 virtual void ReadImpl(ReadIterator& iter, size_t& length) override
45 {
46 name_labels = std::vector<std::string>();
47 std::string label;
48 unsigned char label_len = ReadData<unsigned char>(iter, length);
49 while (label_len != 0)
50 {
51 label = ReadRawString(iter, length, label_len);
52 label_len = ReadData<unsigned char>(iter, length);
53 name_labels.push_back(label);
54 }
55
56 type_code = ReadData<unsigned short>(iter, length);
57 class_code = ReadData<unsigned short>(iter, length);
58 }
59
60 virtual void WriteImpl(WriteContainer& container) const override
61 {
62 for (int i = 0; i < name_labels.size(); ++i)
63 {
64 WriteData<unsigned char>(static_cast<unsigned char>(name_labels[i].size()), container);
65 WriteRawString(name_labels[i], container);
66 }
67 WriteData<unsigned char>(0, container);
68
69 WriteData<unsigned short>(type_code, container);
70 WriteData<unsigned short>(class_code, container);
71 }
72
73 virtual Json::Value SerializeImpl() const override
74 {
75 Json::Value output;
76
77 std::string name = "";
78 for (int i = 0; i < name_labels.size(); ++i)
79 {
80 name += name_labels[i] + ".";
81 }
82 output["identification"] = name;
83
84 output["type_code"] = type_code;
85 output["class_code"] = class_code;
86
87 return output;
88 }
89
90 private:
91 std::vector<std::string> name_labels;
92 unsigned short type_code;
93 unsigned short class_code;
94 };
95}
virtual void ReadImpl(ReadIterator &iter, size_t &length) override
void SetClassCode(const unsigned short class_code_)
unsigned short class_code
void SetNameLabels(const std::vector< std::string > &name_labels_)
void SetTypeCode(const unsigned short type_code_)
virtual void WriteImpl(WriteContainer &container) const override
std::vector< std::string > name_labels
unsigned short type_code
const unsigned short GetClassCode() const
virtual Json::Value SerializeImpl() const override
const unsigned short GetTypeCode() const
const std::vector< std::string > & GetNameLabels() const
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
std::string ReadRawString(ReadIterator &iter, size_t &length, const size_t size)
void WriteRawString(const std::string &s, WriteContainer &container)
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator