Blink DB Documentation v1.0.0
Blink DB Documentation
Loading...
Searching...
No Matches
resp_encoder.hpp
Go to the documentation of this file.
1
14#ifndef RESP_ENCODER_HPP
15#define RESP_ENCODER_HPP
16
17#include <string>
18
20public:
30 static std::string simpleString(const std::string &str) {
31 return "+" + str + "\r\n";
32 }
33
44 static std::string error(const std::string &message) {
45 return "-ERR " + message + "\r\n";
46 }
47
57 static std::string integer(int value) {
58 return ":" + std::to_string(value) + "\r\n";
59 }
60
75 static std::string bulkString(const std::string &str, const bool isNull) {
76 if (isNull) {
77 return "$-1\r\n";
78 }
79 if (str.empty()) {
80 return "$0\r\n\r\n";
81 }
82 return "$" + std::to_string(str.length()) + "\r\n" + str + "\r\n";
83 }
84};
85
86#endif
Definition resp_encoder.hpp:19
static std::string simpleString(const std::string &str)
Converts a simple string to RESP format.
Definition resp_encoder.hpp:30
static std::string bulkString(const std::string &str, const bool isNull)
Converts a bulk string to RESP format.
Definition resp_encoder.hpp:75
static std::string error(const std::string &message)
Converts an error message to RESP format.
Definition resp_encoder.hpp:44
static std::string integer(int value)
Used to encode an integer to RESP format.
Definition resp_encoder.hpp:57