aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2/entry_codec.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-05-25 23:27:06 -0700
committerChris Lu <chris.lu@gmail.com>2018-05-25 23:27:06 -0700
commitc34feca59c6ebfdf7ffd8b24b1c827a2f18f263b (patch)
tree3d0d42531be4e9a7eda050394fb996d865100956 /weed/filer2/entry_codec.go
parent6de84c64c67eb0e1161ad1b627917d466d49e6c6 (diff)
downloadseaweedfs-c34feca59c6ebfdf7ffd8b24b1c827a2f18f263b.tar.xz
seaweedfs-c34feca59c6ebfdf7ffd8b24b1c827a2f18f263b.zip
refactoring
Diffstat (limited to 'weed/filer2/entry_codec.go')
-rw-r--r--weed/filer2/entry_codec.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/weed/filer2/entry_codec.go b/weed/filer2/entry_codec.go
new file mode 100644
index 000000000..7d2b2da37
--- /dev/null
+++ b/weed/filer2/entry_codec.go
@@ -0,0 +1,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
+}