diff --git a/include/communicate/commu_options.h b/include/communicate/commu_options.h new file mode 100644 index 0000000..9e8ce1d --- /dev/null +++ b/include/communicate/commu_options.h @@ -0,0 +1,8 @@ +#pragma once + +#define MSG_VERSION 0x0 + +namespace Net{ + + +} diff --git a/include/communicate/message.h b/include/communicate/message.h new file mode 100644 index 0000000..76e3eb6 --- /dev/null +++ b/include/communicate/message.h @@ -0,0 +1,144 @@ +#pragma once +#include +#include +#include +#include +#include + +#include "communicate/commu_options.h" +#include "utils/sha256_generator.h" + +using std::string; +using std::vector; +using std::shared_ptr; +using std::queue; + +namespace Net { + +class Option { +public: + Option(const string &key, const string &value); + + Option(const Option &o); + + Option(Option &&o) noexcept; + + Option& operator=(const Option &o); + + Option& operator=(Option &&o) noexcept; + + const string &getKey() const; + + const string &getValue() const; + + void updateValue(const string &value); + +private: + shared_ptr key; + shared_ptr value; +}; + +class MessageFactory; + +class Message { +public: + + Message() noexcept; + + void setHead(int32_t tid, int16_t type); + + void addOption(const string &key, const string &value); + + const string &getValue(const string &key) const; + + void pushData(void *const buf, size_t size); + + int32_t getTID() const; + + const vector &getData() const; + + void clear(); + +private: + friend MessageFactory; + + int32_t tid = -1; + int16_t version = MSG_VERSION; + int16_t type = 0x0; + vector