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
9f35e3ef
Commit
9f35e3ef
authored
Mar 13, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add function to marshal raw nodes to json
fixes
https://github.com/ipfs/go-ipfs/issues/6076
parent
1bc88945
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
merkledag_test.go
merkledag_test.go
+22
-0
raw.go
raw.go
+6
-0
No files found.
merkledag_test.go
View file @
9f35e3ef
...
@@ -3,6 +3,7 @@ package merkledag_test
...
@@ -3,6 +3,7 @@ package merkledag_test
import
(
import
(
"bytes"
"bytes"
"context"
"context"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
...
@@ -640,6 +641,27 @@ func TestCidRawDoesnNeedData(t *testing.T) {
...
@@ -640,6 +641,27 @@ func TestCidRawDoesnNeedData(t *testing.T) {
}
}
}
}
func
TestRawToJson
(
t
*
testing
.
T
)
{
rawData
:=
[]
byte
{
1
,
2
,
3
,
4
}
nd
:=
NewRawNode
(
rawData
)
encoded
,
err
:=
nd
.
MarshalJSON
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
res
interface
{}
err
=
json
.
Unmarshal
(
encoded
,
&
res
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
resBytes
,
ok
:=
res
.
(
string
)
if
!
ok
{
t
.
Fatal
(
"expected to marshal to a string"
)
}
if
string
(
rawData
)
!=
resBytes
{
t
.
Fatal
(
"failed to round-trip bytes"
)
}
}
func
TestGetManyDuplicate
(
t
*
testing
.
T
)
{
func
TestGetManyDuplicate
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
...
...
raw.go
View file @
9f35e3ef
package
merkledag
package
merkledag
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"github.com/ipfs/go-block-format"
"github.com/ipfs/go-block-format"
...
@@ -94,4 +95,9 @@ func (rn *RawNode) Stat() (*ipld.NodeStat, error) {
...
@@ -94,4 +95,9 @@ func (rn *RawNode) Stat() (*ipld.NodeStat, error) {
},
nil
},
nil
}
}
// MarshalJSON is required for our "ipfs dag" commands.
func
(
rn
*
RawNode
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
string
(
rn
.
RawData
()))
}
var
_
ipld
.
Node
=
(
*
RawNode
)(
nil
)
var
_
ipld
.
Node
=
(
*
RawNode
)(
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