blob: e6e258d82cf517a96e8512e32196442a732f577a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
|