From 4d686b2f47ffe615b1019e1387d821f37d3f7d55 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 25 Jul 2023 08:30:31 +0530 Subject: [PATCH] Nicer string repr for operations --- tools/rsync/algorithm.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/rsync/algorithm.go b/tools/rsync/algorithm.go index 4f768a2b2..8f5d00c27 100644 --- a/tools/rsync/algorithm.go +++ b/tools/rsync/algorithm.go @@ -16,6 +16,7 @@ import ( "hash" "io" "os" + "strconv" "github.com/zeebo/xxh3" "golang.org/x/exp/slices" @@ -76,6 +77,21 @@ type Operation struct { Data []byte } +func (self Operation) String() string { + ans := "{" + self.Type.String() + " " + switch self.Type { + case OpBlock: + ans += strconv.FormatUint(self.BlockIndex, 10) + case OpBlockRange: + ans += strconv.FormatUint(self.BlockIndex, 10) + " to " + strconv.FormatUint(self.BlockIndexEnd, 10) + case OpData: + ans += strconv.Itoa(len(self.Data)) + case OpHash: + ans += hex.EncodeToString(self.Data) + } + return ans + "}" +} + var bin = binary.LittleEndian func (self Operation) SerializeSize() int {