mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 06:36:24 +00:00
Work on adding overall checksum support
This commit is contained in:
parent
d676886ab8
commit
e125f803b3
2 changed files with 74 additions and 10 deletions
|
|
@ -14,6 +14,8 @@ import (
|
|||
"hash"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/zeebo/xxh3"
|
||||
)
|
||||
|
||||
// If no BlockSize is specified in the rsync instance, this value is used.
|
||||
|
|
@ -32,6 +34,36 @@ const (
|
|||
OpBlockRange
|
||||
)
|
||||
|
||||
type xxh3_128 struct {
|
||||
xxh3.Hasher
|
||||
}
|
||||
|
||||
func (self *xxh3_128) Sum(b []byte) []byte {
|
||||
s := self.Sum128()
|
||||
pos := len(b)
|
||||
if len(b)+16 < cap(b) {
|
||||
var x [16]byte
|
||||
b = append(b, x[:]...)
|
||||
} else {
|
||||
b = b[:len(b)+16]
|
||||
}
|
||||
binary.BigEndian.PutUint64(b[pos:], s.Hi)
|
||||
binary.BigEndian.PutUint64(b[pos+8:], s.Lo)
|
||||
return b
|
||||
}
|
||||
|
||||
func new_xxh3_64() hash.Hash64 {
|
||||
ans := xxh3.New()
|
||||
ans.Reset()
|
||||
return ans
|
||||
}
|
||||
|
||||
func new_xxh3_128() hash.Hash {
|
||||
ans := new(xxh3_128)
|
||||
ans.Reset()
|
||||
return ans
|
||||
}
|
||||
|
||||
// Instruction to mutate target to align to source.
|
||||
type Operation struct {
|
||||
Type OpType
|
||||
|
|
@ -163,9 +195,11 @@ type rsync struct {
|
|||
BlockSize int
|
||||
|
||||
// This must be non-nil before using any functions
|
||||
hasher hash.Hash64
|
||||
hasher_constructor func() hash.Hash64
|
||||
buffer []byte
|
||||
hasher hash.Hash64
|
||||
hasher_constructor func() hash.Hash64
|
||||
checksummer_constructor func() hash.Hash
|
||||
checksummer hash.Hash
|
||||
buffer []byte
|
||||
}
|
||||
|
||||
func (r *rsync) SetHasher(c func() hash.Hash64) {
|
||||
|
|
@ -173,6 +207,11 @@ func (r *rsync) SetHasher(c func() hash.Hash64) {
|
|||
r.hasher = c()
|
||||
}
|
||||
|
||||
func (r *rsync) SetChecksummer(c func() hash.Hash) {
|
||||
r.checksummer_constructor = c
|
||||
r.checksummer = c()
|
||||
}
|
||||
|
||||
// If the target length is known the number of hashes in the
|
||||
// signature can be determined.
|
||||
func (r *rsync) BlockHashCount(targetLength int64) (count int64) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue