-
Notifications
You must be signed in to change notification settings - Fork 32
/
types.go
65 lines (53 loc) · 1.31 KB
/
types.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
package rsync
import "github.com/gokrazy/rsync/internal/rsyncwire"
// rsync/rsync.h:struct sum_buf
type SumBuf struct {
Offset int64
Len int64
Index int32
Sum1 uint32
Sum2 [16]byte
}
// TODO: remove connection.go:sumHead in favor of this type
type SumHead struct {
// “number of blocks” (openrsync)
// “how many chunks” (rsync)
ChecksumCount int32
// “block length in the file” (openrsync)
// maximum (1 << 29) for older rsync, (1 << 17) for newer
BlockLength int32
// “long checksum length” (openrsync)
ChecksumLength int32
// “terminal (remainder) block length” (openrsync)
// RemainderLength is flength % BlockLength
RemainderLength int32
Sums []SumBuf
}
func (sh *SumHead) ReadFrom(c *rsyncwire.Conn) error {
var err error
sh.ChecksumCount, err = c.ReadInt32()
if err != nil {
return err
}
sh.BlockLength, err = c.ReadInt32()
if err != nil {
return err
}
sh.ChecksumLength, err = c.ReadInt32()
if err != nil {
return err
}
sh.RemainderLength, err = c.ReadInt32()
if err != nil {
return err
}
return nil
}
func (sh *SumHead) WriteTo(c *rsyncwire.Conn) error {
var buf rsyncwire.Buffer
buf.WriteInt32(sh.ChecksumCount)
buf.WriteInt32(sh.BlockLength)
buf.WriteInt32(sh.ChecksumLength)
buf.WriteInt32(sh.RemainderLength)
return c.WriteString(buf.String())
}