forked from balacode/go-delta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delta_go_string.go
44 lines (40 loc) · 1.32 KB
/
delta_go_string.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
// -----------------------------------------------------------------------------
// github.com/balacode/go-delta go-delta/[delta_go_string.go]
// (c) [email protected] License: MIT
// -----------------------------------------------------------------------------
package delta
import (
"bytes"
"fmt"
)
// GoString returns a Go-syntax representation of the Delta structure.
// It implements the fmt.GoStringer interface.
func (ob Delta) GoString() string {
var buf bytes.Buffer
write := func(args ...string) {
for _, s := range args {
buf.WriteString(s)
}
}
str := func(v interface{}) string {
return fmt.Sprintf("%#v", v)
}
write("Delta{", "\n",
"\t", "sourceSize: ", str(ob.sourceSize), ",\n",
"\t", "sourceHash: ", str(ob.sourceHash), ",\n",
"\t", "targetSize: ", str(ob.targetSize), ",\n",
"\t", "targetHash: ", str(ob.targetHash), ",\n",
"\t", "newCount: ", str(ob.newCount), ",\n",
"\t", "oldCount: ", str(ob.oldCount), ",\n",
"\t", "parts: []deltaPart{\n",
)
for _, pt := range ob.parts {
write("\t\t{",
"sourceLoc: ", str(pt.sourceLoc), ", ",
"size: ", str(pt.size), ", ",
"data: ", str(pt.data), "}\n")
}
write("\t},\n}")
return buf.String()
} // GoString
// end