Make mvccpb::KeyValue a member of etcdv3::keyValue instead of

inheriting from it.
This commit is contained in:
arches 2016-07-26 10:04:26 -04:00
parent 16936603b5
commit 60383a502c
11 changed files with 25 additions and 30 deletions

View File

@ -4,8 +4,8 @@
#include "etcd/Response.hpp" #include "etcd/Response.hpp"
#include "v3/include/Transaction.hpp" #include "v3/include/Transaction.hpp"
#include "v3/include/AsyncTxnResponse.hpp" #include "v3/include/AsyncTxnResponse.hpp"
#include "v3/include/Action.hpp"
#include <cpprest/http_client.h>
#include <string> #include <string>
#include <grpc++/grpc++.h> #include <grpc++/grpc++.h>

View File

@ -15,7 +15,7 @@ etcd::Response::Response(const etcdv3::V3Response& reply)
for(unsigned int index = 0; index < val.size(); index++) for(unsigned int index = 0; index < val.size(); index++)
{ {
_values.push_back(Value(val[index])); _values.push_back(Value(val[index]));
_keys.push_back(val[index].key()); _keys.push_back(val[index].kvs.key());
} }
} }
else else

View File

@ -12,15 +12,15 @@ etcd::Value::Value()
} }
etcd::Value::Value(etcdv3::KeyValue const & kvs) etcd::Value::Value(etcdv3::KeyValue const & kv)
{ {
dir=false; dir=false;
_key=kvs.key(); _key=kv.kvs.key();
value=kvs.value(); value=kv.kvs.value();
created=kvs.create_revision(); created=kv.kvs.create_revision();
modified=kvs.mod_revision(); modified=kv.kvs.mod_revision();
leaseId = kvs.lease(); leaseId = kv.kvs.lease();
_ttl = kvs.get_ttl(); _ttl = kv.get_ttl();
} }
std::string const & etcd::Value::key() const std::string const & etcd::Value::key() const

View File

@ -6,11 +6,11 @@
namespace etcdv3 namespace etcdv3
{ {
class KeyValue : public mvccpb::KeyValue class KeyValue
{ {
public: public:
KeyValue(); KeyValue();
KeyValue(const mvccpb::KeyValue& from); mvccpb::KeyValue kvs;
void set_ttl(int ttl); void set_ttl(int ttl);
int get_ttl() const; int get_ttl() const;
private: private:

View File

@ -17,14 +17,16 @@ void etcdv3::AsyncDeleteRangeResponse::ParseResponse(std::string const& key, boo
//get all previous values //get all previous values
for(int cnt=0; cnt < resp.prev_kvs_size(); cnt++) for(int cnt=0; cnt < resp.prev_kvs_size(); cnt++)
{ {
values.push_back(resp.prev_kvs(cnt)); etcdv3::KeyValue kv;
kv.kvs.CopyFrom(resp.prev_kvs(cnt));
values.push_back(kv);
} }
if(!prefix) if(!prefix)
{ {
prev_value = values[0]; prev_value = values[0];
value = values[0]; value = values[0];
value.clear_value(); value.kvs.clear_value();
values.clear(); values.clear();
} }

View File

@ -33,8 +33,6 @@ etcdv3::AsyncRangeResponse etcdv3::AsyncGetAction::ParseResponse()
else else
{ {
range_resp.ParseResponse(reply, parameters.withPrefix); range_resp.ParseResponse(reply, parameters.withPrefix);
//range_resp.set_action(etcdv3::GET_ACTION);
//range_resp.isPrefix = parameters.withPrefix;
} }
return range_resp; return range_resp;
} }

View File

@ -5,7 +5,7 @@
void etcdv3::AsyncLeaseGrantResponse::ParseResponse(LeaseGrantResponse& resp) void etcdv3::AsyncLeaseGrantResponse::ParseResponse(LeaseGrantResponse& resp)
{ {
index = resp.header().revision(); index = resp.header().revision();
value.set_lease(resp.id()); value.kvs.set_lease(resp.id());
value.set_ttl(resp.ttl()); value.set_ttl(resp.ttl());
error_message = resp.error(); error_message = resp.error();
} }

View File

@ -16,8 +16,9 @@ void etcdv3::AsyncRangeResponse::ParseResponse(RangeResponse& resp, bool prefix)
{ {
for(int index=0; index < resp.kvs_size(); index++) for(int index=0; index < resp.kvs_size(); index++)
{ {
etcdv3::KeyValue kvs(resp.kvs(index)); etcdv3::KeyValue kv;
values.push_back(kvs); kv.kvs.CopyFrom(resp.kvs(index));
values.push_back(kv);
} }
if(!prefix) if(!prefix)

View File

@ -27,7 +27,7 @@ void etcdv3::AsyncTxnResponse::ParseResponse(std::string const& key, bool prefix
auto put_resp = resp.response_put(); auto put_resp = resp.response_put();
if(put_resp.has_prev_kv()) if(put_resp.has_prev_kv())
{ {
prev_value.CopyFrom(put_resp.prev_kv()); prev_value.kvs.CopyFrom(put_resp.prev_kv());
} }
} }
else if(ResponseOp::ResponseCase::kResponseDeleteRange == resp.response_case()) else if(ResponseOp::ResponseCase::kResponseDeleteRange == resp.response_case())
@ -35,7 +35,7 @@ void etcdv3::AsyncTxnResponse::ParseResponse(std::string const& key, bool prefix
AsyncDeleteRangeResponse response; AsyncDeleteRangeResponse response;
response.ParseResponse(key,prefix,*(resp.mutable_response_delete_range())); response.ParseResponse(key,prefix,*(resp.mutable_response_delete_range()));
prev_value.CopyFrom(response.get_prev_value()); prev_value.kvs.CopyFrom(response.get_prev_value().kvs);
values = response.get_values(); values = response.get_values();
value = response.get_value(); value = response.get_value();

View File

@ -17,17 +17,17 @@ void etcdv3::AsyncWatchResponse::ParseResponse(WatchResponse& reply)
{ {
action = etcdv3::SET_ACTION; action = etcdv3::SET_ACTION;
} }
value = event.kv(); value.kvs = event.kv();
} }
else if(mvccpb::Event::EventType::Event_EventType_DELETE == event.type()) else if(mvccpb::Event::EventType::Event_EventType_DELETE == event.type())
{ {
action = etcdv3::DELETE_ACTION; action = etcdv3::DELETE_ACTION;
value = event.kv(); value.kvs = event.kv();
} }
if(event.has_prev_kv()) if(event.has_prev_kv())
{ {
prev_value = event.prev_kv(); prev_value.kvs = event.prev_kv();
} }
// just store the first occurence of the key in values. // just store the first occurence of the key in values.
// this is done so tas client will not need to change their behaviour. // this is done so tas client will not need to change their behaviour.

View File

@ -5,12 +5,6 @@ etcdv3::KeyValue::KeyValue()
ttl = 0; ttl = 0;
} }
etcdv3::KeyValue::KeyValue(const mvccpb::KeyValue& from)
: mvccpb::KeyValue(from)
{
ttl =0;
}
void etcdv3::KeyValue::set_ttl(int ttl) void etcdv3::KeyValue::set_ttl(int ttl)
{ {
this->ttl = ttl; this->ttl = ttl;