Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
b4de6cce
Commit
b4de6cce
authored
Nov 14, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
object put: Fixed putting objects with JSON encoding
parent
eb696d9a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
18 deletions
+33
-18
core/commands2/object.go
core/commands2/object.go
+33
-18
No files found.
core/commands2/object.go
View file @
b4de6cce
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment