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
301a925a
Commit
301a925a
authored
Jul 04, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt
parent
dcdb1e32
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
65 deletions
+61
-65
coding.go
coding.go
+42
-43
merkledag.go
merkledag.go
+19
-22
No files found.
coding.go
View file @
301a925a
...
@@ -16,7 +16,7 @@ func (n *Node) Unmarshal(encoded []byte) error {
...
@@ -16,7 +16,7 @@ func (n *Node) Unmarshal(encoded []byte) error {
pbnl
:=
pbn
.
GetLinks
()
pbnl
:=
pbn
.
GetLinks
()
n
.
Links
=
make
([]
*
Link
,
len
(
pbnl
))
n
.
Links
=
make
([]
*
Link
,
len
(
pbnl
))
for
i
,
l
:=
range
(
pbnl
)
{
for
i
,
l
:=
range
pbnl
{
n
.
Links
[
i
]
=
&
Link
{
Name
:
l
.
GetName
(),
Size
:
l
.
GetTsize
()}
n
.
Links
[
i
]
=
&
Link
{
Name
:
l
.
GetName
(),
Size
:
l
.
GetTsize
()}
h
,
err
:=
mh
.
Cast
(
l
.
GetHash
())
h
,
err
:=
mh
.
Cast
(
l
.
GetHash
())
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -49,7 +49,7 @@ func (n *Node) Marshal() ([]byte, error) {
...
@@ -49,7 +49,7 @@ func (n *Node) Marshal() ([]byte, error) {
func
(
n
*
Node
)
getPBNode
()
*
PBNode
{
func
(
n
*
Node
)
getPBNode
()
*
PBNode
{
pbn
:=
&
PBNode
{}
pbn
:=
&
PBNode
{}
pbn
.
Links
=
make
([]
*
PBLink
,
len
(
n
.
Links
))
pbn
.
Links
=
make
([]
*
PBLink
,
len
(
n
.
Links
))
for
i
,
l
:=
range
(
n
.
Links
)
{
for
i
,
l
:=
range
n
.
Links
{
pbn
.
Links
[
i
]
=
&
PBLink
{}
pbn
.
Links
[
i
]
=
&
PBLink
{}
pbn
.
Links
[
i
]
.
Name
=
&
l
.
Name
pbn
.
Links
[
i
]
.
Name
=
&
l
.
Name
pbn
.
Links
[
i
]
.
Tsize
=
&
l
.
Size
pbn
.
Links
[
i
]
.
Tsize
=
&
l
.
Size
...
@@ -59,4 +59,3 @@ func (n *Node) getPBNode() *PBNode {
...
@@ -59,4 +59,3 @@ func (n *Node) getPBNode() *PBNode {
pbn
.
Data
=
n
.
Data
pbn
.
Data
=
n
.
Data
return
pbn
return
pbn
}
}
merkledag.go
View file @
301a925a
...
@@ -11,7 +11,6 @@ type Node struct {
...
@@ -11,7 +11,6 @@ type Node struct {
Data
[]
byte
Data
[]
byte
}
}
// An IPFS Merkle DAG Link
// An IPFS Merkle DAG Link
type
Link
struct
{
type
Link
struct
{
// utf string name. should be unique per object
// utf string name. should be unique per object
...
@@ -24,10 +23,8 @@ type Link struct {
...
@@ -24,10 +23,8 @@ type Link struct {
Hash
mh
.
Multihash
Hash
mh
.
Multihash
}
}
type
EncodedNode
[]
byte
type
EncodedNode
[]
byte
func
(
n
*
Node
)
Size
()
(
uint64
,
error
)
{
func
(
n
*
Node
)
Size
()
(
uint64
,
error
)
{
d
,
err
:=
n
.
Marshal
()
d
,
err
:=
n
.
Marshal
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -35,7 +32,7 @@ func (n *Node) Size() (uint64, error) {
...
@@ -35,7 +32,7 @@ func (n *Node) Size() (uint64, error) {
}
}
s
:=
uint64
(
len
(
d
))
s
:=
uint64
(
len
(
d
))
for
_
,
l
:=
range
(
n
.
Links
)
{
for
_
,
l
:=
range
n
.
Links
{
s
+=
l
.
Size
s
+=
l
.
Size
}
}
return
s
,
nil
return
s
,
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