-
Notifications
You must be signed in to change notification settings - Fork 2
/
rpc.go
66 lines (50 loc) · 1.03 KB
/
rpc.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
package backend
import (
"context"
"log"
"github.com/pojntfx/r3map/pkg/services"
)
type RPCBackend struct {
ctx context.Context
remote *services.BackendRemote
size int64
verbose bool
}
func NewRPCBackend(
ctx context.Context,
remote *services.BackendRemote,
size int64,
verbose bool,
) *RPCBackend {
return &RPCBackend{ctx, remote, size, verbose}
}
func (b *RPCBackend) ReadAt(p []byte, off int64) (n int, err error) {
if b.verbose {
log.Printf("ReadAt(len(p) = %v, off = %v)", len(p), off)
}
r, err := b.remote.ReadAt(b.ctx, len(p), off)
if err != nil {
return -1, err
}
n = r.N
copy(p, r.P)
return
}
func (b *RPCBackend) WriteAt(p []byte, off int64) (n int, err error) {
if b.verbose {
log.Printf("WriteAt(len(p) = %v, off = %v)", len(p), off)
}
return b.remote.WriteAt(b.ctx, p, off)
}
func (b *RPCBackend) Size() (int64, error) {
if b.verbose {
log.Println("Size()")
}
return b.size, nil
}
func (b *RPCBackend) Sync() error {
if b.verbose {
log.Println("Sync()")
}
return b.remote.Sync(b.ctx)
}