Skip to content

Commit

Permalink
clientv3: make ops and compares non-opaque and mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
heyitsanthony committed Mar 21, 2017
1 parent 3a1368d commit 648a46c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clientv3/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ func ModRevision(key string) Cmp {
return Cmp{Key: []byte(key), Target: pb.Compare_MOD}
}

func (cmp *Cmp) KeyBytes() []byte { return cmp.Key }
func (cmp *Cmp) WithKeyBytes(key []byte) { cmp.Key = key }
func (cmp *Cmp) ValueBytes() []byte {
if tu, ok := cmp.TargetUnion.(*pb.Compare_Value); ok {
return tu.Value
}
return nil
}
func (cmp *Cmp) WithValueBytes(v []byte) { cmp.TargetUnion.(*pb.Compare_Value).Value = v }

func mustInt64(val interface{}) int64 {
if v, ok := val.(int64); ok {
return v
Expand Down
9 changes: 9 additions & 0 deletions clientv3/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ type Op struct {
leaseID LeaseID
}

// accesors / mutators

func (op Op) KeyBytes() []byte { return op.key }
func (op *Op) WithKeyBytes(key []byte) { op.key = key }
func (op Op) EndBytes() []byte { return op.end }
func (op *Op) WithEndBytes(end []byte) { op.end = end }
func (op Op) ValueBytes() []byte { return op.val }
func (op *Op) WithValueBytes(v []byte) { op.val = v }

func (op Op) toRangeRequest() *pb.RangeRequest {
if op.t != tRange {
panic("op.t != tRange")
Expand Down

0 comments on commit 648a46c

Please sign in to comment.