Skip to content

Commit

Permalink
doc: add DecoderChooser to example
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Sep 12, 2023
1 parent 44e7f1e commit cd8ec78
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions traversal/example_select_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
// set themselves up in our multicodec registry so the LinkSystem can use
// them for encoding (when a LinkPrototype says so) and decoding (when a CID's
// codec code says so).
"github.com/ipld/go-ipld-prime/codec/dagcbor"

_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
_ "github.com/ipld/go-ipld-prime/codec/dagjson"
_ "github.com/ipld/go-ipld-prime/codec/raw"

Expand Down Expand Up @@ -105,7 +106,13 @@ func ExampleSelectLinks() {
// load bytes of the block
byts := loadBytes(ccb)
// decode the block into Node form
n, err := ipld.Decode(byts, dagcbor.Decode)
decoder, err := cidlink.DefaultLinkSystem().DecoderChooser(cidlink.Link{Cid: ccb})
if err != nil {
panic(err)
}
// we could just use `dagcbor.Decode` here, but by using the DecoderChooser
// we make sure we get the right one for the CID.
n, err := ipld.Decode(byts, decoder)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit cd8ec78

Please sign in to comment.