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
ld
go-ld-prime
Commits
bd402871
Unverified
Commit
bd402871
authored
Apr 28, 2020
by
Eric Myhre
Committed by
GitHub
Apr 28, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #53 from ipld/bugs/cbor-marshall
Fix marshalling error
parents
50e2df1e
2edb45a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
codec/dagcbor/marshal.go
codec/dagcbor/marshal.go
+1
-0
codec/dagcbor/roundtrip_test.go
codec/dagcbor/roundtrip_test.go
+40
-0
No files found.
codec/dagcbor/marshal.go
View file @
bd402871
...
...
@@ -134,6 +134,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk
.
Tagged
=
true
tk
.
Tag
=
linkTag
_
,
err
=
sink
.
Step
(
tk
)
tk
.
Tagged
=
false
return
err
default
:
return
fmt
.
Errorf
(
"schemafree link emission only supported by this codec for CID type links!"
)
...
...
codec/dagcbor/roundtrip_test.go
View file @
bd402871
...
...
@@ -2,11 +2,17 @@ package dagcbor
import
(
"bytes"
"context"
"crypto/rand"
"io"
"testing"
cid
"github.com/ipfs/go-cid"
.
"github.com/warpfork/go-wish"
ipld
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/fluent"
cidlink
"github.com/ipld/go-ipld-prime/linking/cid"
basicnode
"github.com/ipld/go-ipld-prime/node/basic"
)
...
...
@@ -62,3 +68,37 @@ func TestRoundtripScalar(t *testing.T) {
Wish
(
t
,
nb
.
Build
(),
ShouldEqual
,
simple
)
})
}
func
TestRoundtripLinksAndBytes
(
t
*
testing
.
T
)
{
lb
:=
cidlink
.
LinkBuilder
{
cid
.
Prefix
{
Version
:
1
,
Codec
:
0x71
,
MhType
:
0x17
,
MhLength
:
4
,
}}
buf
:=
bytes
.
Buffer
{}
lnk
,
err
:=
lb
.
Build
(
context
.
Background
(),
ipld
.
LinkContext
{},
n
,
func
(
ipld
.
LinkContext
)
(
io
.
Writer
,
ipld
.
StoreCommitter
,
error
)
{
return
&
buf
,
func
(
lnk
ipld
.
Link
)
error
{
return
nil
},
nil
},
)
Require
(
t
,
err
,
ShouldEqual
,
nil
)
var
linkByteNode
=
fluent
.
MustBuildMap
(
basicnode
.
Style__Map
{},
4
,
func
(
na
fluent
.
MapAssembler
)
{
nva
:=
na
.
AssembleEntry
(
"Link"
)
nva
.
AssignLink
(
lnk
)
nva
=
na
.
AssembleEntry
(
"Bytes"
)
bytes
:=
make
([]
byte
,
100
)
_
,
_
=
rand
.
Read
(
bytes
)
nva
.
AssignBytes
(
bytes
)
})
buf
.
Reset
()
err
=
Encoder
(
linkByteNode
,
&
buf
)
Require
(
t
,
err
,
ShouldEqual
,
nil
)
nb
:=
basicnode
.
Style__Map
{}
.
NewBuilder
()
err
=
Decoder
(
nb
,
&
buf
)
Require
(
t
,
err
,
ShouldEqual
,
nil
)
reconstructed
:=
nb
.
Build
()
Wish
(
t
,
reconstructed
,
ShouldEqual
,
linkByteNode
)
}
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