-
Notifications
You must be signed in to change notification settings - Fork 365
/
Copy pathentry.go
49 lines (45 loc) · 1.03 KB
/
entry.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
45
46
47
48
49
package catalog
import (
"github.com/treeverse/lakefs/pkg/graveler"
"github.com/treeverse/lakefs/pkg/ident"
"google.golang.org/protobuf/proto"
)
func ValueToEntry(value *graveler.Value) (*Entry, error) {
if value == nil {
return nil, nil
}
var ent Entry
err := proto.Unmarshal(value.Data, &ent)
if err != nil {
return nil, err
}
return &ent, nil
}
func EntryToValue(entry *Entry) (*graveler.Value, error) {
// marshal data using pb
data, err := proto.Marshal(entry)
if err != nil {
return nil, err
}
// calculate entry identity
checksum := ident.NewAddressWriter().
MarshalInt64(entry.Size).
MarshalString(entry.ETag).
MarshalStringMap(entry.Metadata).
MarshalStringOpt(entry.ContentType). // optional in order to keep identity of old entries without content-type
Identity()
return &graveler.Value{
Identity: checksum,
Data: data,
}, nil
}
func MustEntryToValue(entry *Entry) *graveler.Value {
if entry == nil {
return nil
}
v, err := EntryToValue(entry)
if err != nil {
panic(err)
}
return v
}