package dagcbor import ( "io" "github.com/polydawn/refmt/cbor" "gitlab.dms3.io/ld/go-ld-prime" "gitlab.dms3.io/ld/go-ld-prime/multicodec" ) var ( _ ld.Decoder = Decode _ ld.Encoder = Encode ) func init() { multicodec.RegisterEncoder(0x71, Encode) multicodec.RegisterDecoder(0x71, Decode) } func Decode(na ld.NodeAssembler, r io.Reader) error { // Probe for a builtin fast path. Shortcut to that if possible. type detectFastPath interface { DecodeDagCbor(io.Reader) error } if na2, ok := na.(detectFastPath); ok { return na2.DecodeDagCbor(r) } // Okay, generic builder path. return Unmarshal(na, cbor.NewDecoder(cbor.DecodeOptions{}, r), true) } func Encode(n ld.Node, w io.Writer) error { // Probe for a builtin fast path. Shortcut to that if possible. type detectFastPath interface { EncodeDagCbor(io.Writer) error } if n2, ok := n.(detectFastPath); ok { return n2.EncodeDagCbor(w) } // Okay, generic inspection path. return Marshal(n, cbor.NewEncoder(w), true) }