Пример #1
0
func p2h(w io.Writer, r io.Reader) error {
	br := bufio.NewReader(r)

	for {
		p, err := br.ReadBytes('\n')
		if err != nil {
			if err == io.EOF {
				return nil
			}
			return err
		}
		p = p[:len(p)-1] // remove \n

		hdr := mc.Header(p)

		_, err = w.Write(hdr)
		if err != nil {
			return err
		}
	}
}
Пример #2
0
func filter(w io.Writer, r io.Reader, path string) error {
	hdr := mc.Header([]byte(path))

	// as we decode, write everything to a buffer.
	buf := bytes.NewBuffer(nil)
	r = io.TeeReader(r, buf)

	return decode(r, func(codec *mux.Multicodec, value interface{}) error {
		defer buf.Reset()

		// c.Last is the last multicodec encoded or decoded.
		// skip headers which do not match.
		if !bytes.Equal(hdr, codec.Last.Header()) {
			return nil
		}

		_, err := io.Copy(w, buf)
		if err != nil && err != io.EOF {
			return err
		}
		return nil
	})
}
Пример #3
0
func init() {
	Header = mc.Header([]byte("/protobuf"))
	HeaderMsgio = mc.Header([]byte("/protobuf/msgio"))
}
Пример #4
0
func init() {
	Header = mc.Header([]byte("/msgio"))
}
Пример #5
0
func init() {
	HeaderPath = "/json"
	HeaderMsgioPath = "/json/msgio"
	Header = mc.Header([]byte(HeaderPath))
	HeaderMsgio = mc.Header([]byte(HeaderMsgioPath))
}
Пример #6
0
func init() {
	Header = mc.Header([]byte("/mdagv1"))
}
Пример #7
0
func codecWithPath(path string) mc.Multicodec {
	hdr := mc.Header([]byte(path))
	codec := mux.CodecWithHeader(hdr, mux.StandardMux().Codecs)
	return codec
}
Пример #8
0
func header(w io.Writer, path string) error {
	_, err := w.Write(mc.Header([]byte(path)))
	return err
}
Пример #9
0
func init() {
	HeaderPath = "/cbor"
	Header = mc.Header([]byte(HeaderPath))
}
Пример #10
0
func init() {
	Header = mc.Header([]byte("/multicodec"))
}