@cryptotaxi247 / kubo / commits / 537f94a31

object get: Fixed protobuf marshaling

Matt Bell committed Nov 13, 2014 at 23:52 UTC 537f94a3184ce4b752cc179a29d5a95bf66a231f
1 file changed +26 -7
core/commands2/object.go
+26 -7
@@ -7,6 +7,8 @@ import (
7 "io"
8 "io/ioutil"
9
10 + mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
11 +
12 cmds "github.com/jbenet/go-ipfs/commands"
13 core "github.com/jbenet/go-ipfs/core"
14 dag "github.com/jbenet/go-ipfs/merkledag"
@@ -108,23 +110,23 @@ var objectGetCmd = &cmds.Command{
110 Tagline: "Get and serialize the DAG node named by <key>",
111 ShortDescription: `
112 'ipfs object get' is a plumbing command for retreiving DAG nodes.
111 -It serializes the DAG node to the format specified by the "--encoding" flag.
112 -It outputs to stdout, and <key> is a base58 encoded multihash.
113 +It serializes the DAG node to the format specified by the "--encoding"
114 +flag. It outputs to stdout, and <key> is a base58 encoded multihash.
115 `,
116 LongDescription: `
117 'ipfs object get' is a plumbing command for retreiving DAG nodes.
116 -It serializes the DAG node to the format specified by the "--encoding" flag.
117 -It outputs to stdout, and <key> is a base58 encoded multihash.
118 +It serializes the DAG node to the format specified by the "--encoding"
119 +flag. It outputs to stdout, and <key> is a base58 encoded multihash.
120
121 This command outputs data in the following encodings:
122 * "protobuf"
123 * "json"
124 * "xml"
123 -(Specified by the "--encoding" or "-enc" flags)`,
125 +(Specified by the "--encoding" or "-enc" flag)`,
126 },
127
128 Arguments: []cmds.Argument{
127 - cmds.StringArg("key", true, false, "Key of the object to retrieve\n(in base58-encoded multihash format)"),
129 + cmds.StringArg("key", true, false, "Key of the object to retrieve (in base58-encoded multihash format)"),
130 },
131 Run: func(req cmds.Request) (interface{}, error) {
132 n, err := req.Context().GetNode()
@@ -160,7 +162,24 @@ This command outputs data in the following encodings:
162 Type: &Node{},
163 Marshalers: cmds.MarshalerMap{
164 cmds.EncodingType("protobuf"): func(res cmds.Response) ([]byte, error) {
163 - object := res.Output().(*dag.Node)
165 + node := res.Output().(*Node)
166 +
167 + // convert the Node object into a real dag.Node
168 + object := new(dag.Node)
169 + object.Data = node.Data
170 + object.Links = make([]*dag.Link, len(node.Links))
171 + for i, link := range node.Links {
172 + hash, err := mh.FromB58String(link.Hash)
173 + if err != nil {
174 + return nil, err
175 + }
176 + object.Links[i] = &dag.Link{
177 + Name: link.Name,
178 + Size: link.Size,
179 + Hash: hash,
180 + }
181 + }
182 +
183 return object.Marshal()
184 },
185 },