diff --git a/README.md b/README.md index 762922d450ff48280278855b8d1b9de82608688d..c481214cf9af9fe0a5ea453fef9edc0570967d51 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **An implementation of the IPLD [DAG-PB](https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md) spec for [go-ipld-prime](https://github.com/ipld/go-ipld-prime/)** -Use `Decoder(ipld.NodeAssembler, io.Reader)` and `Encoder(ipld.Node, io.Writer)` directly, or import this package to have this codec registered into the go-ipld-prime CID link loader. +Use `Decode(ipld.NodeAssembler, io.Reader)` and `Encode(ipld.Node, io.Writer)` directly, or import this package to have this codec registered into the go-ipld-prime CID link loader. Nodes encoded with this codec _must_ conform to the DAG-PB spec. Specifically, they should have the non-optional fields shown in the DAG-PB schema: diff --git a/basics_test.go b/basics_test.go index 27b59c7da5dc9958e3b1ba980ea49320ba5b3b47..06bad950c50e1814c65d31b6feb17bc02ed14521 100644 --- a/basics_test.go +++ b/basics_test.go @@ -96,7 +96,7 @@ func runTest(t *testing.T, bytsHex string, expected pbNode) { roundTrip := func(t *testing.T, node ipld.Node) { var buf bytes.Buffer - if err := Encoder(node, &buf); err != nil { + if err := Encode(node, &buf); err != nil { t.Fatal(err) } @@ -108,7 +108,7 @@ func runTest(t *testing.T, bytsHex string, expected pbNode) { t.Run("basicnode", func(t *testing.T) { nb := basicnode.Prototype__Map{}.NewBuilder() - err := Decoder(nb, bytes.NewReader(byts)) + err := Decode(nb, bytes.NewReader(byts)) if err != nil { t.Fatal(err) } @@ -120,7 +120,7 @@ func runTest(t *testing.T, bytsHex string, expected pbNode) { t.Run("typed", func(t *testing.T) { nb := Type.PBNode.NewBuilder() - err := Decoder(nb, bytes.NewReader(byts)) + err := Decode(nb, bytes.NewReader(byts)) if err != nil { t.Fatal(err) } @@ -180,7 +180,7 @@ func TestNodeWithTwoUnsortedLinks(t *testing.T) { }) var buf bytes.Buffer - if err := Encoder(node, &buf); err != nil { + if err := Encode(node, &buf); err != nil { t.Fatal(err) } if hex.EncodeToString(buf.Bytes()) != encoded { @@ -217,11 +217,11 @@ func TestNodeWithStableSortedLinks(t *testing.T) { }) var buf bytes.Buffer - if err := Encoder(node, &buf); err != nil { + if err := Encode(node, &buf); err != nil { t.Fatal(err) } nb := basicnode.Prototype__Map{}.NewBuilder() - err := Decoder(nb, bytes.NewReader(buf.Bytes())) + err := Decode(nb, bytes.NewReader(buf.Bytes())) if err != nil { t.Fatal(err) } diff --git a/doc.go b/doc.go index 68663b6f486d5e5de2fafefca21e3f6c93461af3..fda961f365139f94567e58af391642dfc3f2629d 100644 --- a/doc.go +++ b/doc.go @@ -3,8 +3,9 @@ Package dagpb provides an implementation of the IPLD DAG-PB spec (https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md) for go-ipld-prime (https://github.com/ipld/go-ipld-prime/). -Use Decoder() and Encoder() directly, or import this package to have this codec -registered into the go-ipld-prime CID link loader. +Use Decode() and Encode() directly, or import this package to have this codec +registered into the go-ipld-prime multicodec registry and available from the +cidlink.DefaultLinkSystem. Nodes encoded with this codec _must_ conform to the DAG-PB spec. Specifically, they should have the non-optional fields shown in the DAG-PB schema: @@ -21,7 +22,7 @@ they should have the non-optional fields shown in the DAG-PB schema: } Use dagpb.Type.PBNode and friends directly for strictness guarantees. Basic -ipld.Node's will need to have the appropraite fields (and no others) to +ipld.Node's will need to have the appropriate fields (and no others) to successfully encode using this codec. */ package dagpb diff --git a/multicodec.go b/multicodec.go index a6079a9e633094060f86d3264a6148794b5ff6ab..73839d5dd4ad39f82b07dafbe071c39c5b59ccc6 100644 --- a/multicodec.go +++ b/multicodec.go @@ -8,32 +8,32 @@ import ( ) var ( - _ ipld.Decoder = Decoder - _ ipld.Encoder = Encoder + _ ipld.Decode = Decode + _ ipld.Encode = Encode ) func init() { - multicodec.RegisterDecoder(0x70, Decoder) - multicodec.RegisterEncoder(0x70, Encoder) + multicodec.RegisterDecoder(0x70, Decode) + multicodec.RegisterEncoder(0x70, Encode) } -// Decoder provides an IPLD codec decode interface for DAG-PB data. Provide a +// Decode provides an IPLD codec decode interface for DAG-PB data. Provide a // compatible NodeAssembler and a byte source to unmarshal a DAG-PB IPLD Node. // Use the NodeAssembler from the PBNode type for safest construction // (Type.PBNode.NewBuilder()). A Map assembler will also work. // This function is registered via the go-ipld-prime link loader for multicodec // code 0x70 when this package is invoked via init. -func Decoder(na ipld.NodeAssembler, r io.Reader) error { +func Decode(na ipld.NodeAssembler, r io.Reader) error { return Unmarshal(na, r) } -// Encoder provides an IPLD codec encode interface for DAG-PB data. Provide a +// Encode provides an IPLD codec encode interface for DAG-PB data. Provide a // conforming Node and a destination for bytes to marshal a DAG-PB IPLD Node. // The Node must strictly conform to the DAG-PB schema // (https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md). // For safest use, build Nodes using the Type.PBNode type. // This function is registered via the go-ipld-prime link loader for multicodec // code 0x70 when this package is invoked via init. -func Encoder(n ipld.Node, w io.Writer) error { +func Encode(n ipld.Node, w io.Writer) error { return Marshal(n, w) }