ToList is a default implementation of KeyToList. It picks up all valid versions of the key, skipping over deleted or expired keys.
(key []byte, itr *Iterator)
| 85 | // ToList is a default implementation of KeyToList. It picks up all valid versions of the key, |
| 86 | // skipping over deleted or expired keys. |
| 87 | func (st *Stream) ToList(key []byte, itr *Iterator) (*pb.KVList, error) { |
| 88 | list := &pb.KVList{} |
| 89 | for ; itr.Valid(); itr.Next() { |
| 90 | item := itr.Item() |
| 91 | if item.IsDeletedOrExpired() { |
| 92 | break |
| 93 | } |
| 94 | if !bytes.Equal(key, item.Key()) { |
| 95 | // Break out on the first encounter with another key. |
| 96 | break |
| 97 | } |
| 98 | |
| 99 | valCopy, err := item.ValueCopy(nil) |
| 100 | if err != nil { |
| 101 | return nil, err |
| 102 | } |
| 103 | kv := &pb.KV{ |
| 104 | Key: item.KeyCopy(nil), |
| 105 | Value: valCopy, |
| 106 | UserMeta: []byte{item.UserMeta()}, |
| 107 | Version: item.Version(), |
| 108 | ExpiresAt: item.ExpiresAt(), |
| 109 | } |
| 110 | list.Kv = append(list.Kv, kv) |
| 111 | if st.db.opt.NumVersionsToKeep == 1 { |
| 112 | break |
| 113 | } |
| 114 | |
| 115 | if item.DiscardEarlierVersions() { |
| 116 | break |
| 117 | } |
| 118 | } |
| 119 | return list, nil |
| 120 | } |
| 121 | |
| 122 | // keyRange is [start, end), including start, excluding end. Do ensure that the start, |
| 123 | // end byte slices are owned by keyRange struct. |