Beispiel #1
0
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
	})
}
Beispiel #2
0
func codecByName(name string) mc.Multicodec {
	for _, c := range codecs {
		if name == string(mc.HeaderPath(c.Header())) {
			return c
		}
	}
	return nil
}
Beispiel #3
0
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)
}
Beispiel #4
0
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
		}
	}
}
Beispiel #5
0
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
}