-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarshal.go
More file actions
42 lines (37 loc) · 884 Bytes
/
Copy pathmarshal.go
File metadata and controls
42 lines (37 loc) · 884 Bytes
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
package main
import (
"github.com/golang/protobuf/proto"
"io/ioutil"
"log"
)
// Data and PBNode are two protobuf message struct
// this only works for small data
func marshal(by []byte, typ Data_DataType) []byte {
pbdata := new(Data)
pbdata.Type = &typ
pbdata.Data = by
pbdata.Filesize = proto.Uint64(uint64(len(by))) // return a pointer of integer
//pbdata.Blocksizes = []uint64{} // blocksizes of child nodes
enc, err := proto.Marshal(pbdata)
if err != nil {
log.Fatal(err)
}
pbnode := new(PBNode)
pbnode.Data = enc
mdata, err := proto.Marshal(pbnode)
if err != nil {
log.Fatal(err)
}
// links := make([]*PBLink, 0, 10)
// pbnode.Links = links
return mdata
}
func marshalSmallFile(filename string) string {
buf, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
mdata := marshal(buf, Data_File)
mh := multiHash(mdata)
return mh
}