Adam Sadovsky | 8db7443 | 2015-05-29 17:37:32 -0700 | [diff] [blame^] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package watchable |
| 6 | |
| 7 | import ( |
| 8 | "v.io/syncbase/x/ref/services/syncbase/store" |
| 9 | ) |
| 10 | |
| 11 | type snapshot struct { |
| 12 | isn store.Snapshot |
| 13 | st *wstore |
| 14 | } |
| 15 | |
| 16 | var _ store.Snapshot = (*snapshot)(nil) |
| 17 | |
| 18 | func newSnapshot(st *wstore) *snapshot { |
| 19 | return &snapshot{ |
| 20 | isn: st.ist.NewSnapshot(), |
| 21 | st: st, |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // Close implements the store.Snapshot interface. |
| 26 | func (s *snapshot) Close() error { |
| 27 | return s.isn.Close() |
| 28 | } |
| 29 | |
| 30 | // Get implements the store.StoreReader interface. |
| 31 | func (s *snapshot) Get(key, valbuf []byte) ([]byte, error) { |
| 32 | if !s.st.managesKey(key) { |
| 33 | return s.isn.Get(key, valbuf) |
| 34 | } |
| 35 | return getVersioned(s.isn, key, valbuf) |
| 36 | } |
| 37 | |
| 38 | // Scan implements the store.StoreReader interface. |
| 39 | func (s *snapshot) Scan(start, limit []byte) store.Stream { |
| 40 | if !s.st.managesRange(start, limit) { |
| 41 | return s.isn.Scan(start, limit) |
| 42 | } |
| 43 | return newStreamVersioned(s.isn, start, limit) |
| 44 | } |