aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/response.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol/response.h')
-rw-r--r--src/protocol/response.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/protocol/response.h b/src/protocol/response.h
new file mode 100644
index 0000000..e6e258d
--- /dev/null
+++ b/src/protocol/response.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: BSD-3-Clause
+
+#ifndef INVERTER_TOOLS_PROTOCOL_RESPONSE_H
+#define INVERTER_TOOLS_PROTOCOL_RESPONSE_H
+
+#include <memory>
+#include "../formatter/formatter.h"
+
+namespace protocol {
+
+typedef std::shared_ptr<formatter::Formattable> formattable_ptr;
+
+class BaseResponse {
+protected:
+ std::shared_ptr<char> raw_;
+ size_t rawSize_;
+
+public:
+ BaseResponse(std::shared_ptr<char> raw, size_t rawSize);
+ virtual ~BaseResponse() = default;
+ virtual bool validate() = 0;
+ virtual void unpack() = 0;
+ virtual formattable_ptr format(formatter::Format format) = 0;
+};
+
+
+class ErrorResponse : public BaseResponse {
+private:
+ std::string error_;
+
+public:
+ explicit ErrorResponse(std::string error)
+ : BaseResponse(nullptr, 0), error_(std::move(error)) {}
+
+ bool validate() override {
+ return true;
+ }
+ void unpack() override {}
+ formattable_ptr format(formatter::Format format) override;
+};
+
+}
+
+#endif //INVERTER_TOOLS_PROTOCOL_RESPONSE_H