Browse Source

clientv3: make ops and compares non-opaque and mutable

Fixes #7250
Anthony Romano 8 years ago
parent
commit
f9b6066dd6
2 changed files with 37 additions and 0 deletions
  1. 17 0
      clientv3/compare.go
  2. 20 0
      clientv3/op.go

+ 17 - 0
clientv3/compare.go

@@ -82,6 +82,23 @@ func ModRevision(key string) Cmp {
 	return Cmp{Key: []byte(key), Target: pb.Compare_MOD}
 	return Cmp{Key: []byte(key), Target: pb.Compare_MOD}
 }
 }
 
 
+// KeyBytes returns the byte slice holding with the comparison key.
+func (cmp *Cmp) KeyBytes() []byte { return cmp.Key }
+
+// WithKeyBytes sets the byte slice for the comparison key.
+func (cmp *Cmp) WithKeyBytes(key []byte) { cmp.Key = key }
+
+// ValueBytes returns the byte slice holding the comparison value, if any.
+func (cmp *Cmp) ValueBytes() []byte {
+	if tu, ok := cmp.TargetUnion.(*pb.Compare_Value); ok {
+		return tu.Value
+	}
+	return nil
+}
+
+// WithValueBytes sets the byte slice for the comparison's value.
+func (cmp *Cmp) WithValueBytes(v []byte) { cmp.TargetUnion.(*pb.Compare_Value).Value = v }
+
 func mustInt64(val interface{}) int64 {
 func mustInt64(val interface{}) int64 {
 	if v, ok := val.(int64); ok {
 	if v, ok := val.(int64); ok {
 		return v
 		return v

+ 20 - 0
clientv3/op.go

@@ -69,6 +69,26 @@ type Op struct {
 	leaseID LeaseID
 	leaseID LeaseID
 }
 }
 
 
+// accesors / mutators
+
+// KeyBytes returns the byte slice holding the Op's key.
+func (op Op) KeyBytes() []byte { return op.key }
+
+// WithKeyBytes sets the byte slice for the Op's key.
+func (op *Op) WithKeyBytes(key []byte) { op.key = key }
+
+// RangeBytes returns the byte slice holding with the Op's range end, if any.
+func (op Op) RangeBytes() []byte { return op.end }
+
+// WithRangeBytes sets the byte slice for the Op's range end.
+func (op *Op) WithRangeBytes(end []byte) { op.end = end }
+
+// ValueBytes returns the byte slice holding the Op's value, if any.
+func (op Op) ValueBytes() []byte { return op.val }
+
+// WithValueBytes sets the byte slice for the Op's value.
+func (op *Op) WithValueBytes(v []byte) { op.val = v }
+
 func (op Op) toRangeRequest() *pb.RangeRequest {
 func (op Op) toRangeRequest() *pb.RangeRequest {
 	if op.t != tRange {
 	if op.t != tRange {
 		panic("op.t != tRange")
 		panic("op.t != tRange")