Commit 1483091b authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Add method to produce multiple copies of a response through concatenation

parent 8d31a6a6
......@@ -165,3 +165,14 @@ RedisEncodedResponse Formatter::raftEntries(const std::vector<RaftEntry> &entrie
RedisEncodedResponse Formatter::noauth(const std::string &str) {
return RedisEncodedResponse(SSTR("-NOAUTH " << str << "\r\n"));
}
RedisEncodedResponse Formatter::multiply(const RedisEncodedResponse &resp, size_t factor) {
qdb_assert(factor >= 1);
std::ostringstream ss;
for(size_t i = 0; i < factor; i++) {
ss << resp.val;
}
return RedisEncodedResponse(ss.str());
}
......@@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef __QUARKDB_FORMATTER_H__
#define __QUARKDB_FORMATTER_H__
#ifndef QUARKDB_FORMATTER_H
#define QUARKDB_FORMATTER_H
#include <rocksdb/status.h>
#include "redis/RedisEncodedResponse.hh"
......@@ -54,6 +54,8 @@ public:
static RedisEncodedResponse simpleRedisRequest(const RedisRequest &req);
static RedisEncodedResponse redisRequest(const RedisRequest &req);
static RedisEncodedResponse multiply(const RedisEncodedResponse &resp, size_t factor);
};
}
......
......@@ -34,6 +34,10 @@ TEST(Response, T1) {
ASSERT_EQ(Formatter::null().val, "$-1\r\n");
ASSERT_EQ(Formatter::status("test").val, "+test\r\n");
ASSERT_EQ(Formatter::noauth("asdf").val, "-NOAUTH asdf\r\n");
ASSERT_EQ(
Formatter::multiply(Formatter::noauth("you shall not pass"), 3).val,
"-NOAUTH you shall not pass\r\n-NOAUTH you shall not pass\r\n-NOAUTH you shall not pass\r\n"
);
}
TEST(ArrayResponseBuilder, BasicSanity) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment