aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/response.h
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-06-07 01:40:32 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-12-02 04:05:15 +0300
commit3aed59276c2b7275603f6da18377b77718948667 (patch)
tree86816d82ab02b6e4761175d599f5749490706792 /src/protocol/response.h
parentd86ca1e596b094cba101e0e3e6c8cdb71f8116e9 (diff)
wipp17
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