예제 #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
	})
}
예제 #2
0
파일: convert.go 프로젝트: mildred/go-ipld
func codecByName(name string) mc.Multicodec {
	for _, c := range codecs {
		if name == string(mc.HeaderPath(c.Header())) {
			return c
		}
	}
	return nil
}
예제 #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)
}
예제 #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
		}
	}
}
예제 #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
}