event.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package etcd3
  14. import (
  15. "github.com/coreos/etcd/clientv3"
  16. "github.com/coreos/etcd/mvcc/mvccpb"
  17. )
  18. type event struct {
  19. key string
  20. value []byte
  21. rev int64
  22. isDeleted bool
  23. isCreated bool
  24. }
  25. func parseKV(kv *mvccpb.KeyValue) *event {
  26. return &event{
  27. key: string(kv.Key),
  28. value: kv.Value,
  29. rev: kv.ModRevision,
  30. isDeleted: false,
  31. isCreated: kv.ModRevision == kv.CreateRevision,
  32. }
  33. }
  34. func parseEvent(e *clientv3.Event) *event {
  35. return &event{
  36. key: string(e.Kv.Key),
  37. value: e.Kv.Value,
  38. rev: e.Kv.ModRevision,
  39. isDeleted: e.Type == clientv3.EventTypeDelete,
  40. isCreated: e.IsCreate(),
  41. }
  42. }