@cryptotaxi247 / kubo / commits / 4373bf9d7

merkledag: fix json marshalling of pbnode

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Dec 13, 2016 at 10:47 UTC 4373bf9d75eb7fa24f88ce9e0af1c2307161d900
2 files changed +23
merkledag/node.go
+10
@@ -2,6 +2,7 @@ package merkledag
2
3 import (
4 "context"
5 + "encoding/json"
6 "fmt"
7
8 node "gx/ipfs/QmRSU5EqqWVZSNdbU51yXmVoF1uNw3JgTNB6RaiL7DZM16/go-ipld-node"
@@ -228,6 +229,15 @@ func (n *ProtoNode) Loggable() map[string]interface{} {
229 }
230 }
231
232 +func (n *ProtoNode) MarshalJSON() ([]byte, error) {
233 + out := map[string]interface{}{
234 + "data": n.data,
235 + "links": n.links,
236 + }
237 +
238 + return json.Marshal(out)
239 +}
240 +
241 func (n *ProtoNode) Cid() *cid.Cid {
242 if n.encoded != nil && n.cached != nil {
243 return n.cached
test/sharness/t0053-dag.sh
+13
@@ -46,6 +46,19 @@ test_dag_cmd() {
46 test_cmp file2 out2 &&
47 test_cmp file3 out3
48 '
49 +
50 + test_expect_success "add a normal file" '
51 + HASH=$(echo "foobar" | ipfs add -q)
52 + '
53 +
54 + test_expect_success "can view protobuf object with dag get" '
55 + ipfs dag get $HASH > dag_get_pb_out
56 + '
57 +
58 + test_expect_success "output looks correct" '
59 + echo "{\"data\":\"CAISB2Zvb2JhcgoYBw==\",\"links\":[]}" > dag_get_pb_exp &&
60 + test_cmp dag_get_pb_exp dag_get_pb_out
61 + '
62 }
63
64 # should work offline