1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-02 17:22:42 +08:00

refactor(unixfs/pb) mv proto PBData -> Data, etc.

This commit is contained in:
Brian Tiger Chow
2014-10-22 21:48:35 -07:00
parent 80b573425b
commit a1b61f399c
8 changed files with 63 additions and 63 deletions

View File

@ -207,11 +207,11 @@ type Node struct {
Ipfs *core.IpfsNode
Nd *mdag.Node
dagMod *uio.DagModifier
cached *ftpb.PBData
cached *ftpb.Data
}
func (s *Node) loadData() error {
s.cached = new(ftpb.PBData)
s.cached = new(ftpb.Data)
return proto.Unmarshal(s.Nd.Data, s.cached)
}
@ -224,9 +224,9 @@ func (s *Node) Attr() fuse.Attr {
}
}
switch s.cached.GetType() {
case ftpb.PBData_Directory:
case ftpb.Data_Directory:
return fuse.Attr{Mode: os.ModeDir | 0555}
case ftpb.PBData_File, ftpb.PBData_Raw:
case ftpb.Data_File, ftpb.Data_Raw:
size, err := ft.DataSize(s.Nd.Data)
if err != nil {
log.Error("Error getting size of file: %s", err)

View File

@ -81,11 +81,11 @@ type Node struct {
Ipfs *core.IpfsNode
Nd *mdag.Node
fd *uio.DagReader
cached *ftpb.PBData
cached *ftpb.Data
}
func (s *Node) loadData() error {
s.cached = new(ftpb.PBData)
s.cached = new(ftpb.Data)
return proto.Unmarshal(s.Nd.Data, s.cached)
}
@ -96,9 +96,9 @@ func (s *Node) Attr() fuse.Attr {
s.loadData()
}
switch s.cached.GetType() {
case ftpb.PBData_Directory:
case ftpb.Data_Directory:
return fuse.Attr{Mode: os.ModeDir | 0555}
case ftpb.PBData_File, ftpb.PBData_Raw:
case ftpb.Data_File, ftpb.Data_Raw:
size, _ := s.Nd.Size()
return fuse.Attr{
Mode: 0444,

View File

@ -13,8 +13,8 @@ var ErrMalformedFileFormat = errors.New("malformed data in file format")
var ErrInvalidDirLocation = errors.New("found directory node in unexpected place")
var ErrUnrecognizedType = errors.New("unrecognized node type")
func FromBytes(data []byte) (*pb.PBData, error) {
pbdata := new(pb.PBData)
func FromBytes(data []byte) (*pb.Data, error) {
pbdata := new(pb.Data)
err := proto.Unmarshal(data, pbdata)
if err != nil {
return nil, err
@ -23,8 +23,8 @@ func FromBytes(data []byte) (*pb.PBData, error) {
}
func FilePBData(data []byte, totalsize uint64) []byte {
pbfile := new(pb.PBData)
typ := pb.PBData_File
pbfile := new(pb.Data)
typ := pb.Data_File
pbfile.Type = &typ
pbfile.Data = data
pbfile.Filesize = proto.Uint64(totalsize)
@ -43,8 +43,8 @@ func FilePBData(data []byte, totalsize uint64) []byte {
// Returns Bytes that represent a Directory
func FolderPBData() []byte {
pbfile := new(pb.PBData)
typ := pb.PBData_Directory
pbfile := new(pb.Data)
typ := pb.Data_Directory
pbfile.Type = &typ
data, err := proto.Marshal(pbfile)
@ -56,8 +56,8 @@ func FolderPBData() []byte {
}
func WrapData(b []byte) []byte {
pbdata := new(pb.PBData)
typ := pb.PBData_Raw
pbdata := new(pb.Data)
typ := pb.Data_Raw
pbdata.Data = b
pbdata.Type = &typ
@ -71,7 +71,7 @@ func WrapData(b []byte) []byte {
}
func UnwrapData(data []byte) ([]byte, error) {
pbdata := new(pb.PBData)
pbdata := new(pb.Data)
err := proto.Unmarshal(data, pbdata)
if err != nil {
return nil, err
@ -80,18 +80,18 @@ func UnwrapData(data []byte) ([]byte, error) {
}
func DataSize(data []byte) (uint64, error) {
pbdata := new(pb.PBData)
pbdata := new(pb.Data)
err := proto.Unmarshal(data, pbdata)
if err != nil {
return 0, err
}
switch pbdata.GetType() {
case pb.PBData_Directory:
case pb.Data_Directory:
return 0, errors.New("Cant get data size of directory!")
case pb.PBData_File:
case pb.Data_File:
return pbdata.GetFilesize(), nil
case pb.PBData_Raw:
case pb.Data_Raw:
return uint64(len(pbdata.GetData())), nil
default:
return 0, errors.New("Unrecognized node data type!")
@ -110,8 +110,8 @@ func (mb *MultiBlock) AddBlockSize(s uint64) {
}
func (mb *MultiBlock) GetBytes() ([]byte, error) {
pbn := new(pb.PBData)
t := pb.PBData_File
pbn := new(pb.Data)
t := pb.Data_File
pbn.Type = &t
pbn.Filesize = proto.Uint64(uint64(len(mb.Data)) + mb.subtotal)
pbn.Blocksizes = mb.blocksizes

View File

@ -20,7 +20,7 @@ func TestMultiBlock(t *testing.T) {
t.Fatal(err)
}
pbn := new(pb.PBData)
pbn := new(pb.Data)
err = proto.Unmarshal(b, pbn)
if err != nil {
t.Fatal(err)

View File

@ -20,7 +20,7 @@ type DagModifier struct {
dagserv *mdag.DAGService
curNode *mdag.Node
pbdata *ftpb.PBData
pbdata *ftpb.Data
splitter chunk.BlockSplitter
}

View File

@ -25,23 +25,23 @@ type DagReader struct {
// NewDagReader creates a new reader object that reads the data represented by the given
// node, using the passed in DAGService for data retreival
func NewDagReader(n *mdag.Node, serv *mdag.DAGService) (io.Reader, error) {
pb := new(ftpb.PBData)
pb := new(ftpb.Data)
err := proto.Unmarshal(n.Data, pb)
if err != nil {
return nil, err
}
switch pb.GetType() {
case ftpb.PBData_Directory:
case ftpb.Data_Directory:
// Dont allow reading directories
return nil, ErrIsDir
case ftpb.PBData_File:
case ftpb.Data_File:
return &DagReader{
node: n,
serv: serv,
buf: bytes.NewBuffer(pb.GetData()),
}, nil
case ftpb.PBData_Raw:
case ftpb.Data_Raw:
// Raw block will just be a single level, return a byte buffer
return bytes.NewBuffer(pb.GetData()), nil
default:
@ -64,7 +64,7 @@ func (dr *DagReader) precalcNextBuf() error {
}
nxt = nxtNode
}
pb := new(ftpb.PBData)
pb := new(ftpb.Data)
err := proto.Unmarshal(nxt.Data, pb)
if err != nil {
return err
@ -72,13 +72,13 @@ func (dr *DagReader) precalcNextBuf() error {
dr.position++
switch pb.GetType() {
case ftpb.PBData_Directory:
case ftpb.Data_Directory:
return ft.ErrInvalidDirLocation
case ftpb.PBData_File:
case ftpb.Data_File:
//TODO: this *should* work, needs testing first
//return NewDagReader(nxt, dr.serv)
panic("Not yet handling different layers of indirection!")
case ftpb.PBData_Raw:
case ftpb.Data_Raw:
dr.buf = bytes.NewBuffer(pb.GetData())
return nil
default:

View File

@ -9,7 +9,7 @@ It is generated from these files:
unixfs.proto
It has these top-level messages:
PBData
Data
*/
package unixfs_pb
@ -20,76 +20,76 @@ import math "math"
var _ = proto.Marshal
var _ = math.Inf
type PBData_DataType int32
type Data_DataType int32
const (
PBData_Raw PBData_DataType = 0
PBData_Directory PBData_DataType = 1
PBData_File PBData_DataType = 2
Data_Raw Data_DataType = 0
Data_Directory Data_DataType = 1
Data_File Data_DataType = 2
)
var PBData_DataType_name = map[int32]string{
var Data_DataType_name = map[int32]string{
0: "Raw",
1: "Directory",
2: "File",
}
var PBData_DataType_value = map[string]int32{
var Data_DataType_value = map[string]int32{
"Raw": 0,
"Directory": 1,
"File": 2,
}
func (x PBData_DataType) Enum() *PBData_DataType {
p := new(PBData_DataType)
func (x Data_DataType) Enum() *Data_DataType {
p := new(Data_DataType)
*p = x
return p
}
func (x PBData_DataType) String() string {
return proto.EnumName(PBData_DataType_name, int32(x))
func (x Data_DataType) String() string {
return proto.EnumName(Data_DataType_name, int32(x))
}
func (x *PBData_DataType) UnmarshalJSON(data []byte) error {
value, err := proto.UnmarshalJSONEnum(PBData_DataType_value, data, "PBData_DataType")
func (x *Data_DataType) UnmarshalJSON(data []byte) error {
value, err := proto.UnmarshalJSONEnum(Data_DataType_value, data, "Data_DataType")
if err != nil {
return err
}
*x = PBData_DataType(value)
*x = Data_DataType(value)
return nil
}
type PBData struct {
Type *PBData_DataType `protobuf:"varint,1,req,enum=unixfs.pb.PBData_DataType" json:"Type,omitempty"`
type Data struct {
Type *Data_DataType `protobuf:"varint,1,req,enum=unixfs.pb.Data_DataType" json:"Type,omitempty"`
Data []byte `protobuf:"bytes,2,opt" json:"Data,omitempty"`
Filesize *uint64 `protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"`
Blocksizes []uint64 `protobuf:"varint,4,rep,name=blocksizes" json:"blocksizes,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *PBData) Reset() { *m = PBData{} }
func (m *PBData) String() string { return proto.CompactTextString(m) }
func (*PBData) ProtoMessage() {}
func (m *Data) Reset() { *m = Data{} }
func (m *Data) String() string { return proto.CompactTextString(m) }
func (*Data) ProtoMessage() {}
func (m *PBData) GetType() PBData_DataType {
func (m *Data) GetType() Data_DataType {
if m != nil && m.Type != nil {
return *m.Type
}
return PBData_Raw
return Data_Raw
}
func (m *PBData) GetData() []byte {
func (m *Data) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}
func (m *PBData) GetFilesize() uint64 {
func (m *Data) GetFilesize() uint64 {
if m != nil && m.Filesize != nil {
return *m.Filesize
}
return 0
}
func (m *PBData) GetBlocksizes() []uint64 {
func (m *Data) GetBlocksizes() []uint64 {
if m != nil {
return m.Blocksizes
}
@ -97,5 +97,5 @@ func (m *PBData) GetBlocksizes() []uint64 {
}
func init() {
proto.RegisterEnum("unixfs.pb.PBData_DataType", PBData_DataType_name, PBData_DataType_value)
proto.RegisterEnum("unixfs.pb.Data_DataType", Data_DataType_name, Data_DataType_value)
}

View File

@ -1,6 +1,6 @@
package unixfs.pb;
message PBData {
message Data {
enum DataType {
Raw = 0;
Directory = 1;