blob: ac3694f2b71fe64b46ee005b8d82714ddaaf5dfe [file] [log] [blame]
Adam Sadovsky8db74432015-05-29 17:37:32 -07001// 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
5package watchable
6
7import (
8 "v.io/syncbase/x/ref/services/syncbase/store"
9)
10
11type snapshot struct {
12 isn store.Snapshot
13 st *wstore
14}
15
16var _ store.Snapshot = (*snapshot)(nil)
17
18func 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.
26func (s *snapshot) Close() error {
27 return s.isn.Close()
28}
29
30// Get implements the store.StoreReader interface.
31func (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.
39func (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}