提交 4373bf9d 作者: Jeromy

merkledag: fix json marshalling of pbnode

License: MIT
Signed-off-by: 's avatarJeromy <why@ipfs.io>
上级 4cb236ca
...@@ -2,6 +2,7 @@ package merkledag ...@@ -2,6 +2,7 @@ package merkledag
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
node "gx/ipfs/QmRSU5EqqWVZSNdbU51yXmVoF1uNw3JgTNB6RaiL7DZM16/go-ipld-node" node "gx/ipfs/QmRSU5EqqWVZSNdbU51yXmVoF1uNw3JgTNB6RaiL7DZM16/go-ipld-node"
...@@ -228,6 +229,15 @@ func (n *ProtoNode) Loggable() map[string]interface{} { ...@@ -228,6 +229,15 @@ func (n *ProtoNode) Loggable() map[string]interface{} {
} }
} }
func (n *ProtoNode) MarshalJSON() ([]byte, error) {
out := map[string]interface{}{
"data": n.data,
"links": n.links,
}
return json.Marshal(out)
}
func (n *ProtoNode) Cid() *cid.Cid { func (n *ProtoNode) Cid() *cid.Cid {
if n.encoded != nil && n.cached != nil { if n.encoded != nil && n.cached != nil {
return n.cached return n.cached
......
...@@ -46,6 +46,19 @@ test_dag_cmd() { ...@@ -46,6 +46,19 @@ test_dag_cmd() {
test_cmp file2 out2 && test_cmp file2 out2 &&
test_cmp file3 out3 test_cmp file3 out3
' '
test_expect_success "add a normal file" '
HASH=$(echo "foobar" | ipfs add -q)
'
test_expect_success "can view protobuf object with dag get" '
ipfs dag get $HASH > dag_get_pb_out
'
test_expect_success "output looks correct" '
echo "{\"data\":\"CAISB2Zvb2JhcgoYBw==\",\"links\":[]}" > dag_get_pb_exp &&
test_cmp dag_get_pb_exp dag_get_pb_out
'
} }
# should work offline # should work offline
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论