func paths(w io.Writer, r io.Reader) error { return decode(r, func(codec *mux.Multicodec, v interface{}) error { p := mc.HeaderPath(codec.Last.Header()) _, err := fmt.Fprintln(w, string(p)) return err }) }
func codecByName(name string) mc.Multicodec { for _, c := range codecs { if name == string(mc.HeaderPath(c.Header())) { return c } } return nil }
func init() { // by default, always encode things as cbor defaultCodec = string(mc.HeaderPath(mccbor.Header)) muxCodec = mcmux.MuxMulticodec([]mc.Multicodec{ mccbor.Multicodec(), jsonMulticodec(), pb.Multicodec(), }, selectCodec) }
func h2p(w io.Writer, r io.Reader) error { for { hdr, err := mc.ReadHeader(r) if err != nil { if err == io.EOF { return nil } return err } p := string(mc.HeaderPath(hdr)) _, err = fmt.Fprintln(w, p) if err != nil { return err } } }
func selectCodec(v interface{}, codecs []mc.Multicodec) mc.Multicodec { vn, ok := v.(*ipld.Node) if !ok { return nil } codecKey, err := codecKey(*vn) if err != nil { return nil } for _, c := range codecs { if codecKey == string(mc.HeaderPath(c.Header())) { return c } } return nil // no codec }