MCPcopy Create free account
hub / github.com/egonelbre/exp / writeTree

Function writeTree

ber/tree.go:36–53  ·  view source on GitHub ↗
(out *forkableWriter, tree *Tree)

Source from the content-addressed store, hash-verified

34}
35
36func writeTree(out *forkableWriter, tree *Tree) {
37 if len(tree.Children) == 0 {
38 h := header{tree.Class, tree.Tag, len(tree.Bytes), false, false}
39 marshalHeader(out, h)
40 out.Write(tree.Bytes)
41 } else {
42 head, body := out.fork()
43 last := body
44 for _, sub := range tree.Children {
45 var pre *forkableWriter
46 pre, last = last.fork()
47 writeTree(pre, sub)
48 }
49
50 h := header{tree.Class, tree.Tag, body.Len(), true, false}
51 marshalHeader(head, h)
52 }
53}
54
55func EncodeTree(tree *Tree) ([]byte, error) {
56 var out bytes.Buffer

Callers 1

EncodeTreeFunction · 0.70

Calls 4

marshalHeaderFunction · 0.70
WriteMethod · 0.45
forkMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected