forked from vanadium-archive/go.v23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
row.go
72 lines (61 loc) · 1.57 KB
/
row.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package syncbase
import (
"v.io/v23/context"
"v.io/v23/naming"
wire "v.io/v23/services/syncbase"
"v.io/v23/syncbase/util"
"v.io/v23/vom"
)
func newRow(parentFullName, key string, bh wire.BatchHandle) Row {
// Note, we immediately decode row keys on the server side. See comment in
// server/dispatcher.go for explanation.
fullName := naming.Join(parentFullName, util.Encode(key))
return &row{
c: wire.RowClient(fullName),
fullName: fullName,
key: key,
bh: bh,
}
}
type row struct {
c wire.RowClientMethods
fullName string
key string
bh wire.BatchHandle
}
var _ Row = (*row)(nil)
// Key implements Row.Key.
func (r *row) Key() string {
return r.key
}
// FullName implements Row.FullName.
func (r *row) FullName() string {
return r.fullName
}
// Exists implements Row.Exists.
func (r *row) Exists(ctx *context.T) (bool, error) {
return r.c.Exists(ctx, r.bh)
}
// Get implements Row.Get.
func (r *row) Get(ctx *context.T, value interface{}) error {
rawBytes, err := r.c.Get(ctx, r.bh)
if err != nil {
return err
}
return rawBytes.ToValue(value)
}
// Put implements Row.Put.
func (r *row) Put(ctx *context.T, value interface{}) error {
rawBytes, err := vom.RawBytesFromValue(value)
if err != nil {
return err
}
return r.c.Put(ctx, r.bh, rawBytes)
}
// Delete implements Row.Delete.
func (r *row) Delete(ctx *context.T) error {
return r.c.Delete(ctx, r.bh)
}