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
8a7497fe
Commit
8a7497fe
authored
Mar 11, 2021
by
hannahhoward
Committed by
Eric Myhre
Mar 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(codec/raw): update for linksystem
parent
705307f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
codec/raw/codec.go
codec/raw/codec.go
+8
-3
codec/raw/codec_test.go
codec/raw/codec_test.go
+14
-15
No files found.
codec/raw/codec.go
View file @
8a7497fe
...
...
@@ -12,15 +12,20 @@ import (
"io/ioutil"
ipld
"github.com/ipld/go-ipld-prime"
cidlink
"github.com/ipld/go-ipld-prime/
linking/cid
"
"github.com/ipld/go-ipld-prime/
multicodec
"
)
// TODO(mvdan): make go-ipld-prime use go-multicodec soon
const
rawMulticodec
=
0x55
var
(
_
ipld
.
Decoder
=
Decode
_
ipld
.
Encoder
=
Encode
)
func
init
()
{
cidlink
.
RegisterMulticodecDe
coder
(
rawMulticodec
,
De
code
)
cidlink
.
RegisterMulticodecEn
coder
(
rawMulticodec
,
En
code
)
multicodec
.
RegisterEn
coder
(
rawMulticodec
,
En
code
)
multicodec
.
RegisterDe
coder
(
rawMulticodec
,
De
code
)
}
// Decode implements decoding of a node with the raw codec.
...
...
codec/raw/codec_test.go
View file @
8a7497fe
...
...
@@ -2,7 +2,6 @@ package raw
import
(
"bytes"
"context"
"fmt"
"io"
"testing"
...
...
@@ -48,30 +47,30 @@ func TestRoundtrip(t *testing.T) {
func
TestRoundtripCidlink
(
t
*
testing
.
T
)
{
t
.
Parallel
()
l
b
:=
cidlink
.
Link
Builder
{
Prefix
:
cid
.
Prefix
{
l
p
:=
cidlink
.
Link
Prototype
{
Prefix
:
cid
.
Prefix
{
Version
:
1
,
Codec
:
rawMulticodec
,
MhType
:
0x1
7
,
MhType
:
0x1
3
,
MhLength
:
4
,
}}
node
:=
basicnode
.
NewBytes
([]
byte
(
"hello there"
))
lsys
:=
cidlink
.
DefaultLinkSystem
()
buf
:=
bytes
.
Buffer
{}
lnk
,
err
:=
lb
.
Build
(
context
.
Background
(),
ipld
.
LinkContext
{},
node
,
func
(
ipld
.
LinkContext
)
(
io
.
Writer
,
ipld
.
StoreCommitter
,
error
)
{
return
&
buf
,
func
(
lnk
ipld
.
Link
)
error
{
return
nil
},
nil
},
)
lsys
.
StorageWriteOpener
=
func
(
lnkCtx
ipld
.
LinkContext
)
(
io
.
Writer
,
ipld
.
BlockWriteCommitter
,
error
)
{
return
&
buf
,
func
(
lnk
ipld
.
Link
)
error
{
return
nil
},
nil
}
lsys
.
StorageReadOpener
=
func
(
lnkCtx
ipld
.
LinkContext
,
lnk
ipld
.
Link
)
(
io
.
Reader
,
error
)
{
return
bytes
.
NewReader
(
buf
.
Bytes
()),
nil
}
lnk
,
err
:=
lsys
.
Store
(
ipld
.
LinkContext
{},
lp
,
node
)
qt
.
Assert
(
t
,
err
,
qt
.
IsNil
)
nb
:=
basicnode
.
Prototype__Any
{}
.
NewBuilder
()
err
=
lnk
.
Load
(
context
.
Background
(),
ipld
.
LinkContext
{},
nb
,
func
(
lnk
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
io
.
Reader
,
error
)
{
return
bytes
.
NewReader
(
buf
.
Bytes
()),
nil
},
)
newNode
,
err
:=
lsys
.
Load
(
ipld
.
LinkContext
{},
lnk
,
basicnode
.
Prototype__Any
{})
qt
.
Assert
(
t
,
err
,
qt
.
IsNil
)
qt
.
Assert
(
t
,
n
b
.
Build
()
,
qt
.
DeepEquals
,
node
)
qt
.
Assert
(
t
,
n
ewNode
,
qt
.
DeepEquals
,
node
)
}
// mustOnlyUseRead only exposes Read, hiding Bytes.
...
...
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