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

object put: Fixed putting objects with JSON encoding

parent eb696d9a
......@@ -163,23 +163,10 @@ This command outputs data in the following encodings:
Marshalers: cmds.MarshalerMap{
cmds.EncodingType("protobuf"): func(res cmds.Response) ([]byte, error) {
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)
object, err := deserializeNode(node)
if err != nil {
return nil, err
}
object.Links[i] = &dag.Link{
Name: link.Name,
Size: link.Size,
Hash: hash,
}
}
return object.Marshal()
},
},
......@@ -292,8 +279,16 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, err
switch getObjectEnc(encoding) {
case objectEncodingJSON:
dagnode = new(dag.Node)
err = json.Unmarshal(data, dagnode)
node := new(Node)
err = json.Unmarshal(data, node)
if err != nil {
return nil, err
}
dagnode, err = deserializeNode(node)
if err != nil {
return nil, err
}
case objectEncodingProtobuf:
dagnode, err = dag.Decoded(data)
......@@ -356,3 +351,23 @@ func getOutput(dagnode *dag.Node) (*Object, error) {
return output, nil
}
// converts the Node object into a real dag.Node
func deserializeNode(node *Node) (*dag.Node, error) {
dagnode := new(dag.Node)
dagnode.Data = node.Data
dagnode.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
}
dagnode.Links[i] = &dag.Link{
Name: link.Name,
Size: link.Size,
Hash: hash,
}
}
return dagnode, nil
}
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