in service/http_server/crow_service.cpp [480:513]
std::string CrowService::ParseKVRequest(const KVRequest &kv_request) {
rapidjson::Document doc;
if (kv_request.cmd() == 1) { // SET
doc.SetObject();
rapidjson::Document::AllocatorType &allocator = doc.GetAllocator();
rapidjson::Value val(rapidjson::kObjectType);
doc.AddMember("cmd", "SET", allocator);
doc.AddMember("key", kv_request.key(), allocator);
doc.AddMember("value", kv_request.value(), allocator);
} else if (kv_request.cmd() == 2) { // GET
doc.SetObject();
rapidjson::Document::AllocatorType &allocator = doc.GetAllocator();
rapidjson::Value val(rapidjson::kObjectType);
doc.AddMember("cmd", "GET", allocator);
doc.AddMember("key", kv_request.key(), allocator);
} else if (kv_request.cmd() == 3) { // GETALLVALUES
doc.SetObject();
rapidjson::Document::AllocatorType &allocator = doc.GetAllocator();
rapidjson::Value val(rapidjson::kObjectType);
doc.AddMember("cmd", "GETALLVALUES", allocator);
} else if (kv_request.cmd() == 4) { // GETRANGE
doc.SetObject();
rapidjson::Document::AllocatorType &allocator = doc.GetAllocator();
rapidjson::Value val(rapidjson::kObjectType);
doc.AddMember("cmd", "GETRANGE", allocator);
doc.AddMember("min_key", kv_request.key(), allocator);
doc.AddMember("max_key", kv_request.value(), allocator);
}
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
doc.Accept(writer);
return buffer.GetString();
}