Added new class AsyncRangeResponse
This commit is contained in:
parent
9bb8913540
commit
bd54dffed7
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef __ASYNC_RANGERESPONSE_HPP__
|
||||||
|
#define __ASYNC_RANGERESPONSE_HPP__
|
||||||
|
|
||||||
|
#include <grpc++/grpc++.h>
|
||||||
|
#include "proto/rpc.grpc.pb.h"
|
||||||
|
#include "v3/include/V3Response.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
using grpc::ClientAsyncResponseReader;
|
||||||
|
using grpc::ClientContext;
|
||||||
|
using grpc::CompletionQueue;
|
||||||
|
using grpc::Status;
|
||||||
|
using etcdserverpb::RangeResponse;
|
||||||
|
|
||||||
|
namespace etcdv3
|
||||||
|
{
|
||||||
|
class AsyncRangeResponse : public etcdv3::V3Response
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AsyncRangeResponse(){};
|
||||||
|
AsyncRangeResponse(const AsyncRangeResponse& other);
|
||||||
|
AsyncRangeResponse& operator=(const AsyncRangeResponse& other);
|
||||||
|
RangeResponse reply;
|
||||||
|
Status status;
|
||||||
|
ClientContext context;
|
||||||
|
CompletionQueue cq_;
|
||||||
|
std::unique_ptr<ClientAsyncResponseReader<RangeResponse>> response_reader;
|
||||||
|
AsyncRangeResponse& ParseResponse();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include "v3/include/AsyncRangeResponse.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
etcdv3::AsyncRangeResponse::AsyncRangeResponse(const etcdv3::AsyncRangeResponse& other)
|
||||||
|
{
|
||||||
|
error_code = other.error_code;
|
||||||
|
error_message = other.error_message;
|
||||||
|
index = other.index;
|
||||||
|
action = other.action;
|
||||||
|
values = other.values;
|
||||||
|
}
|
||||||
|
|
||||||
|
etcdv3::AsyncRangeResponse& etcdv3::AsyncRangeResponse::operator=(const etcdv3::AsyncRangeResponse& other)
|
||||||
|
{
|
||||||
|
error_code = other.error_code;
|
||||||
|
error_message = other.error_message;
|
||||||
|
index = other.index;
|
||||||
|
action = other.action;
|
||||||
|
values = other.values;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
etcdv3::AsyncRangeResponse& etcdv3::AsyncRangeResponse::ParseResponse()
|
||||||
|
{
|
||||||
|
action = "get";
|
||||||
|
|
||||||
|
if(reply.kvs_size())
|
||||||
|
{
|
||||||
|
if(reply.more())
|
||||||
|
{
|
||||||
|
for(int index=0; reply.more(); index++)
|
||||||
|
{
|
||||||
|
values.push_back(reply.kvs(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
values.push_back(reply.kvs(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_code=100;
|
||||||
|
error_message="Key not found";
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue