Commit 537f94a3 authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

object get: Fixed protobuf marshaling

parent 4eaf38c6
...@@ -7,6 +7,8 @@ import ( ...@@ -7,6 +7,8 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
cmds "github.com/jbenet/go-ipfs/commands" cmds "github.com/jbenet/go-ipfs/commands"
core "github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
dag "github.com/jbenet/go-ipfs/merkledag" dag "github.com/jbenet/go-ipfs/merkledag"
...@@ -108,23 +110,23 @@ var objectGetCmd = &cmds.Command{ ...@@ -108,23 +110,23 @@ var objectGetCmd = &cmds.Command{
Tagline: "Get and serialize the DAG node named by <key>", Tagline: "Get and serialize the DAG node named by <key>",
ShortDescription: ` ShortDescription: `
'ipfs object get' is a plumbing command for retreiving DAG nodes. 'ipfs object get' is a plumbing command for retreiving DAG nodes.
It serializes the DAG node to the format specified by the "--encoding" flag. It serializes the DAG node to the format specified by the "--encoding"
It outputs to stdout, and <key> is a base58 encoded multihash. flag. It outputs to stdout, and <key> is a base58 encoded multihash.
`, `,
LongDescription: ` LongDescription: `
'ipfs object get' is a plumbing command for retreiving DAG nodes. 'ipfs object get' is a plumbing command for retreiving DAG nodes.
It serializes the DAG node to the format specified by the "--encoding" flag. It serializes the DAG node to the format specified by the "--encoding"
It outputs to stdout, and <key> is a base58 encoded multihash. flag. It outputs to stdout, and <key> is a base58 encoded multihash.
This command outputs data in the following encodings: This command outputs data in the following encodings:
* "protobuf" * "protobuf"
* "json" * "json"
* "xml" * "xml"
(Specified by the "--encoding" or "-enc" flags)`, (Specified by the "--encoding" or "-enc" flag)`,
}, },
Arguments: []cmds.Argument{ Arguments: []cmds.Argument{
cmds.StringArg("key", true, false, "Key of the object to retrieve\n(in base58-encoded multihash format)"), cmds.StringArg("key", true, false, "Key of the object to retrieve (in base58-encoded multihash format)"),
}, },
Run: func(req cmds.Request) (interface{}, error) { Run: func(req cmds.Request) (interface{}, error) {
n, err := req.Context().GetNode() n, err := req.Context().GetNode()
...@@ -160,7 +162,24 @@ This command outputs data in the following encodings: ...@@ -160,7 +162,24 @@ This command outputs data in the following encodings:
Type: &Node{}, Type: &Node{},
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{
cmds.EncodingType("protobuf"): func(res cmds.Response) ([]byte, error) { cmds.EncodingType("protobuf"): func(res cmds.Response) ([]byte, error) {
object := res.Output().(*dag.Node) node := res.Output().(*Node)
// convert the Node object into a real dag.Node
object := new(dag.Node)
object.Data = node.Data
object.Links = make([]*dag.Link, len(node.Links))
for i, link := range node.Links {
hash, err := mh.FromB58String(link.Hash)
if err != nil {
return nil, err
}
object.Links[i] = &dag.Link{
Name: link.Name,
Size: link.Size,
Hash: hash,
}
}
return object.Marshal() return object.Marshal()
}, },
}, },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment