aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2/entry_codec.go
blob: 7fafea3e31144dd89e9bf75d35433eeed9481445 (plain)
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
package filer2

import (
	"os"
	"time"

	"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
	"github.com/gogo/protobuf/proto"
	"fmt"
)

func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) {
	message := &filer_pb.Entry{
		Attributes: &filer_pb.FuseAttributes{
			Crtime:   entry.Attr.Crtime.Unix(),
			Mtime:    entry.Attr.Mtime.Unix(),
			FileMode: uint32(entry.Attr.Mode),
			Uid:      entry.Uid,
			Gid:      entry.Gid,
		},
		Chunks: entry.Chunks,
	}
	return proto.Marshal(message)
}

func (entry *Entry) DecodeAttributesAndChunks(blob []byte) (error) {

	message := &filer_pb.Entry{}

	if err := proto.UnmarshalMerge(blob, message); err != nil {
		return fmt.Errorf("decoding value blob for %s: %v", entry.FullPath, err)
	}

	entry.Attr.Crtime = time.Unix(message.Attributes.Crtime, 0)
	entry.Attr.Mtime = time.Unix(message.Attributes.Mtime, 0)
	entry.Attr.Mode = os.FileMode(message.Attributes.FileMode)
	entry.Attr.Uid = message.Attributes.Uid
	entry.Attr.Gid = message.Attributes.Gid

	entry.Chunks = message.Chunks

	return nil
}