refactor(unixfs/pb) mv proto PBData -> Data, etc.
Brian Tiger Chow committed
Oct 22, 2014 at 21:48 UTC
a1b61f399cf77c909908f546976d9e93eba0e800
8 files changed
+63
-63
fuse/ipns/ipns_unix.go
+4
-4
@@ -207,11 +207,11 @@ type Node struct {
207
Ipfs *core.IpfsNode
208
Nd *mdag.Node
209
dagMod *uio.DagModifier
210
- cached *ftpb.PBData
210
+ cached *ftpb.Data
211
}
212
213
func (s *Node) loadData() error {
214
- s.cached = new(ftpb.PBData)
214
+ s.cached = new(ftpb.Data)
215
return proto.Unmarshal(s.Nd.Data, s.cached)
216
}
217
@@ -224,9 +224,9 @@ func (s *Node) Attr() fuse.Attr {
224
}
225
}
226
switch s.cached.GetType() {
227
- case ftpb.PBData_Directory:
227
+ case ftpb.Data_Directory:
228
return fuse.Attr{Mode: os.ModeDir | 0555}
229
- case ftpb.PBData_File, ftpb.PBData_Raw:
229
+ case ftpb.Data_File, ftpb.Data_Raw:
230
size, err := ft.DataSize(s.Nd.Data)
231
if err != nil {
232
log.Error("Error getting size of file: %s", err)
fuse/readonly/readonly_unix.go
+4
-4
@@ -81,11 +81,11 @@ type Node struct {
81
Ipfs *core.IpfsNode
82
Nd *mdag.Node
83
fd *uio.DagReader
84
- cached *ftpb.PBData
84
+ cached *ftpb.Data
85
}
86
87
func (s *Node) loadData() error {
88
- s.cached = new(ftpb.PBData)
88
+ s.cached = new(ftpb.Data)
89
return proto.Unmarshal(s.Nd.Data, s.cached)
90
}
91
@@ -96,9 +96,9 @@ func (s *Node) Attr() fuse.Attr {
96
s.loadData()
97
}
98
switch s.cached.GetType() {
99
- case ftpb.PBData_Directory:
99
+ case ftpb.Data_Directory:
100
return fuse.Attr{Mode: os.ModeDir | 0555}
101
- case ftpb.PBData_File, ftpb.PBData_Raw:
101
+ case ftpb.Data_File, ftpb.Data_Raw:
102
size, _ := s.Nd.Size()
103
return fuse.Attr{
104
Mode: 0444,
unixfs/format.go
+15
-15
@@ -13,8 +13,8 @@ var ErrMalformedFileFormat = errors.New("malformed data in file format")
13
var ErrInvalidDirLocation = errors.New("found directory node in unexpected place")
14
var ErrUnrecognizedType = errors.New("unrecognized node type")
15
16
-func FromBytes(data []byte) (*pb.PBData, error) {
17
- pbdata := new(pb.PBData)
16
+func FromBytes(data []byte) (*pb.Data, error) {
17
+ pbdata := new(pb.Data)
18
err := proto.Unmarshal(data, pbdata)
19
if err != nil {
20
return nil, err
@@ -23,8 +23,8 @@ func FromBytes(data []byte) (*pb.PBData, error) {
23
}
24
25
func FilePBData(data []byte, totalsize uint64) []byte {
26
- pbfile := new(pb.PBData)
27
- typ := pb.PBData_File
26
+ pbfile := new(pb.Data)
27
+ typ := pb.Data_File
28
pbfile.Type = &typ
29
pbfile.Data = data
30
pbfile.Filesize = proto.Uint64(totalsize)
@@ -43,8 +43,8 @@ func FilePBData(data []byte, totalsize uint64) []byte {
43
44
// Returns Bytes that represent a Directory
45
func FolderPBData() []byte {
46
- pbfile := new(pb.PBData)
47
- typ := pb.PBData_Directory
46
+ pbfile := new(pb.Data)
47
+ typ := pb.Data_Directory
48
pbfile.Type = &typ
49
50
data, err := proto.Marshal(pbfile)
@@ -56,8 +56,8 @@ func FolderPBData() []byte {
56
}
57
58
func WrapData(b []byte) []byte {
59
- pbdata := new(pb.PBData)
60
- typ := pb.PBData_Raw
59
+ pbdata := new(pb.Data)
60
+ typ := pb.Data_Raw
61
pbdata.Data = b
62
pbdata.Type = &typ
63
@@ -71,7 +71,7 @@ func WrapData(b []byte) []byte {
71
}
72
73
func UnwrapData(data []byte) ([]byte, error) {
74
- pbdata := new(pb.PBData)
74
+ pbdata := new(pb.Data)
75
err := proto.Unmarshal(data, pbdata)
76
if err != nil {
77
return nil, err
@@ -80,18 +80,18 @@ func UnwrapData(data []byte) ([]byte, error) {
80
}
81
82
func DataSize(data []byte) (uint64, error) {
83
- pbdata := new(pb.PBData)
83
+ pbdata := new(pb.Data)
84
err := proto.Unmarshal(data, pbdata)
85
if err != nil {
86
return 0, err
87
}
88
89
switch pbdata.GetType() {
90
- case pb.PBData_Directory:
90
+ case pb.Data_Directory:
91
return 0, errors.New("Cant get data size of directory!")
92
- case pb.PBData_File:
92
+ case pb.Data_File:
93
return pbdata.GetFilesize(), nil
94
- case pb.PBData_Raw:
94
+ case pb.Data_Raw:
95
return uint64(len(pbdata.GetData())), nil
96
default:
97
return 0, errors.New("Unrecognized node data type!")
@@ -110,8 +110,8 @@ func (mb *MultiBlock) AddBlockSize(s uint64) {
110
}
111
112
func (mb *MultiBlock) GetBytes() ([]byte, error) {
113
- pbn := new(pb.PBData)
114
- t := pb.PBData_File
113
+ pbn := new(pb.Data)
114
+ t := pb.Data_File
115
pbn.Type = &t
116
pbn.Filesize = proto.Uint64(uint64(len(mb.Data)) + mb.subtotal)
117
pbn.Blocksizes = mb.blocksizes
unixfs/format_test.go
+1
-1
@@ -20,7 +20,7 @@ func TestMultiBlock(t *testing.T) {
20
t.Fatal(err)
21
}
22
23
- pbn := new(pb.PBData)
23
+ pbn := new(pb.Data)
24
err = proto.Unmarshal(b, pbn)
25
if err != nil {
26
t.Fatal(err)
unixfs/io/dagmodifier.go
+1
-1
@@ -20,7 +20,7 @@ type DagModifier struct {
20
dagserv *mdag.DAGService
21
curNode *mdag.Node
22
23
- pbdata *ftpb.PBData
23
+ pbdata *ftpb.Data
24
splitter chunk.BlockSplitter
25
}
26
unixfs/io/dagreader.go
+8
-8
@@ -25,23 +25,23 @@ type DagReader struct {
25
// NewDagReader creates a new reader object that reads the data represented by the given
26
// node, using the passed in DAGService for data retreival
27
func NewDagReader(n *mdag.Node, serv *mdag.DAGService) (io.Reader, error) {
28
- pb := new(ftpb.PBData)
28
+ pb := new(ftpb.Data)
29
err := proto.Unmarshal(n.Data, pb)
30
if err != nil {
31
return nil, err
32
}
33
34
switch pb.GetType() {
35
- case ftpb.PBData_Directory:
35
+ case ftpb.Data_Directory:
36
// Dont allow reading directories
37
return nil, ErrIsDir
38
- case ftpb.PBData_File:
38
+ case ftpb.Data_File:
39
return &DagReader{
40
node: n,
41
serv: serv,
42
buf: bytes.NewBuffer(pb.GetData()),
43
}, nil
44
- case ftpb.PBData_Raw:
44
+ case ftpb.Data_Raw:
45
// Raw block will just be a single level, return a byte buffer
46
return bytes.NewBuffer(pb.GetData()), nil
47
default:
@@ -64,7 +64,7 @@ func (dr *DagReader) precalcNextBuf() error {
64
}
65
nxt = nxtNode
66
}
67
- pb := new(ftpb.PBData)
67
+ pb := new(ftpb.Data)
68
err := proto.Unmarshal(nxt.Data, pb)
69
if err != nil {
70
return err
@@ -72,13 +72,13 @@ func (dr *DagReader) precalcNextBuf() error {
72
dr.position++
73
74
switch pb.GetType() {
75
- case ftpb.PBData_Directory:
75
+ case ftpb.Data_Directory:
76
return ft.ErrInvalidDirLocation
77
- case ftpb.PBData_File:
77
+ case ftpb.Data_File:
78
//TODO: this *should* work, needs testing first
79
//return NewDagReader(nxt, dr.serv)
80
panic("Not yet handling different layers of indirection!")
81
- case ftpb.PBData_Raw:
81
+ case ftpb.Data_Raw:
82
dr.buf = bytes.NewBuffer(pb.GetData())
83
return nil
84
default:
unixfs/pb/unixfs.pb.go
+29
-29
@@ -9,7 +9,7 @@ It is generated from these files:
9
unixfs.proto
10
11
It has these top-level messages:
12
- PBData
12
+ Data
13
*/
14
package unixfs_pb
15
@@ -20,76 +20,76 @@ import math "math"
20
var _ = proto.Marshal
21
var _ = math.Inf
22
23
-type PBData_DataType int32
23
+type Data_DataType int32
24
25
const (
26
- PBData_Raw PBData_DataType = 0
27
- PBData_Directory PBData_DataType = 1
28
- PBData_File PBData_DataType = 2
26
+ Data_Raw Data_DataType = 0
27
+ Data_Directory Data_DataType = 1
28
+ Data_File Data_DataType = 2
29
)
30
31
-var PBData_DataType_name = map[int32]string{
31
+var Data_DataType_name = map[int32]string{
32
0: "Raw",
33
1: "Directory",
34
2: "File",
35
}
36
-var PBData_DataType_value = map[string]int32{
36
+var Data_DataType_value = map[string]int32{
37
"Raw": 0,
38
"Directory": 1,
39
"File": 2,
40
}
41
42
-func (x PBData_DataType) Enum() *PBData_DataType {
43
- p := new(PBData_DataType)
42
+func (x Data_DataType) Enum() *Data_DataType {
43
+ p := new(Data_DataType)
44
*p = x
45
return p
46
}
47
-func (x PBData_DataType) String() string {
48
- return proto.EnumName(PBData_DataType_name, int32(x))
47
+func (x Data_DataType) String() string {
48
+ return proto.EnumName(Data_DataType_name, int32(x))
49
}
50
-func (x *PBData_DataType) UnmarshalJSON(data []byte) error {
51
- value, err := proto.UnmarshalJSONEnum(PBData_DataType_value, data, "PBData_DataType")
50
+func (x *Data_DataType) UnmarshalJSON(data []byte) error {
51
+ value, err := proto.UnmarshalJSONEnum(Data_DataType_value, data, "Data_DataType")
52
if err != nil {
53
return err
54
}
55
- *x = PBData_DataType(value)
55
+ *x = Data_DataType(value)
56
return nil
57
}
58
59
-type PBData struct {
60
- Type *PBData_DataType `protobuf:"varint,1,req,enum=unixfs.pb.PBData_DataType" json:"Type,omitempty"`
61
- Data []byte `protobuf:"bytes,2,opt" json:"Data,omitempty"`
62
- Filesize *uint64 `protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"`
63
- Blocksizes []uint64 `protobuf:"varint,4,rep,name=blocksizes" json:"blocksizes,omitempty"`
64
- XXX_unrecognized []byte `json:"-"`
59
+type Data struct {
60
+ Type *Data_DataType `protobuf:"varint,1,req,enum=unixfs.pb.Data_DataType" json:"Type,omitempty"`
61
+ Data []byte `protobuf:"bytes,2,opt" json:"Data,omitempty"`
62
+ Filesize *uint64 `protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"`
63
+ Blocksizes []uint64 `protobuf:"varint,4,rep,name=blocksizes" json:"blocksizes,omitempty"`
64
+ XXX_unrecognized []byte `json:"-"`
65
}
66
67
-func (m *PBData) Reset() { *m = PBData{} }
68
-func (m *PBData) String() string { return proto.CompactTextString(m) }
69
-func (*PBData) ProtoMessage() {}
67
+func (m *Data) Reset() { *m = Data{} }
68
+func (m *Data) String() string { return proto.CompactTextString(m) }
69
+func (*Data) ProtoMessage() {}
70
71
-func (m *PBData) GetType() PBData_DataType {
71
+func (m *Data) GetType() Data_DataType {
72
if m != nil && m.Type != nil {
73
return *m.Type
74
}
75
- return PBData_Raw
75
+ return Data_Raw
76
}
77
78
-func (m *PBData) GetData() []byte {
78
+func (m *Data) GetData() []byte {
79
if m != nil {
80
return m.Data
81
}
82
return nil
83
}
84
85
-func (m *PBData) GetFilesize() uint64 {
85
+func (m *Data) GetFilesize() uint64 {
86
if m != nil && m.Filesize != nil {
87
return *m.Filesize
88
}
89
return 0
90
}
91
92
-func (m *PBData) GetBlocksizes() []uint64 {
92
+func (m *Data) GetBlocksizes() []uint64 {
93
if m != nil {
94
return m.Blocksizes
95
}
@@ -97,5 +97,5 @@ func (m *PBData) GetBlocksizes() []uint64 {
97
}
98
99
func init() {
100
- proto.RegisterEnum("unixfs.pb.PBData_DataType", PBData_DataType_name, PBData_DataType_value)
100
+ proto.RegisterEnum("unixfs.pb.Data_DataType", Data_DataType_name, Data_DataType_value)
101
}
unixfs/pb/unixfs.proto
+1
-1
@@ -1,6 +1,6 @@
1
package unixfs.pb;
2
3
-message PBData {
3
+message Data {
4
enum DataType {
5
Raw = 0;
6
Directory = 1;