Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
cc425aef
Commit
cc425aef
authored
Oct 05, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed data size reporting
parent
e92bbfbf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
data.pb.go
data.pb.go
+9
-1
data.proto
data.proto
+1
-0
merkledag.go
merkledag.go
+22
-1
No files found.
data.pb.go
View file @
cc425aef
...
@@ -13,7 +13,7 @@ It has these top-level messages:
...
@@ -13,7 +13,7 @@ It has these top-level messages:
*/
*/
package
merkledag
package
merkledag
import
proto
"
github.com/jbenet/go-ipfs/Godeps/_workspace/src/
code.google.com/p/goprotobuf/proto"
import
proto
"code.google.com/p/goprotobuf/proto"
import
math
"math"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
// Reference imports to suppress errors if they are not otherwise used.
...
@@ -59,6 +59,7 @@ func (x *PBData_DataType) UnmarshalJSON(data []byte) error {
...
@@ -59,6 +59,7 @@ func (x *PBData_DataType) UnmarshalJSON(data []byte) error {
type
PBData
struct
{
type
PBData
struct
{
Type
*
PBData_DataType
`protobuf:"varint,1,req,enum=merkledag.PBData_DataType" json:"Type,omitempty"`
Type
*
PBData_DataType
`protobuf:"varint,1,req,enum=merkledag.PBData_DataType" json:"Type,omitempty"`
Data
[]
byte
`protobuf:"bytes,2,opt" json:"Data,omitempty"`
Data
[]
byte
`protobuf:"bytes,2,opt" json:"Data,omitempty"`
Filesize
*
uint64
`protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
}
...
@@ -80,6 +81,13 @@ func (m *PBData) GetData() []byte {
...
@@ -80,6 +81,13 @@ func (m *PBData) GetData() []byte {
return
nil
return
nil
}
}
func
(
m
*
PBData
)
GetFilesize
()
uint64
{
if
m
!=
nil
&&
m
.
Filesize
!=
nil
{
return
*
m
.
Filesize
}
return
0
}
func
init
()
{
func
init
()
{
proto
.
RegisterEnum
(
"merkledag.PBData_DataType"
,
PBData_DataType_name
,
PBData_DataType_value
)
proto
.
RegisterEnum
(
"merkledag.PBData_DataType"
,
PBData_DataType_name
,
PBData_DataType_value
)
}
}
data.proto
View file @
cc425aef
...
@@ -9,4 +9,5 @@ message PBData {
...
@@ -9,4 +9,5 @@ message PBData {
required
DataType
Type
=
1
;
required
DataType
Type
=
1
;
optional
bytes
Data
=
2
;
optional
bytes
Data
=
2
;
optional
uint64
filesize
=
3
;
}
}
merkledag.go
View file @
cc425aef
package
merkledag
package
merkledag
import
(
import
(
"errors"
"fmt"
"fmt"
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
...
@@ -107,6 +108,25 @@ func (n *Node) Size() (uint64, error) {
...
@@ -107,6 +108,25 @@ func (n *Node) Size() (uint64, error) {
return
s
,
nil
return
s
,
nil
}
}
func
(
n
*
Node
)
DataSize
()
(
uint64
,
error
)
{
pbdata
:=
new
(
PBData
)
err
:=
proto
.
Unmarshal
(
n
.
Data
,
pbdata
)
if
err
!=
nil
{
return
0
,
err
}
switch
pbdata
.
GetType
()
{
case
PBData_Directory
:
return
0
,
errors
.
New
(
"Cant get data size of directory!"
)
case
PBData_File
:
return
pbdata
.
GetFilesize
(),
nil
case
PBData_Raw
:
return
uint64
(
len
(
pbdata
.
GetData
())),
nil
default
:
return
0
,
errors
.
New
(
"Unrecognized node data type!"
)
}
}
// Multihash hashes the encoded data of this node.
// Multihash hashes the encoded data of this node.
func
(
n
*
Node
)
Multihash
()
(
mh
.
Multihash
,
error
)
{
func
(
n
*
Node
)
Multihash
()
(
mh
.
Multihash
,
error
)
{
b
,
err
:=
n
.
Encoded
(
false
)
b
,
err
:=
n
.
Encoded
(
false
)
...
@@ -211,11 +231,12 @@ func (n *DAGService) Get(k u.Key) (*Node, error) {
...
@@ -211,11 +231,12 @@ func (n *DAGService) Get(k u.Key) (*Node, error) {
return
Decoded
(
b
.
Data
)
return
Decoded
(
b
.
Data
)
}
}
func
FilePBData
(
data
[]
byte
)
[]
byte
{
func
FilePBData
(
data
[]
byte
,
totalsize
uint64
)
[]
byte
{
pbfile
:=
new
(
PBData
)
pbfile
:=
new
(
PBData
)
typ
:=
PBData_File
typ
:=
PBData_File
pbfile
.
Type
=
&
typ
pbfile
.
Type
=
&
typ
pbfile
.
Data
=
data
pbfile
.
Data
=
data
pbfile
.
Filesize
=
proto
.
Uint64
(
totalsize
)
data
,
err
:=
proto
.
Marshal
(
pbfile
)
data
,
err
:=
proto
.
Marshal
(
pbfile
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment