示例#1
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
		}
	}
}
示例#2
0
func (c *decoder) Decode(v interface{}) error {
	if c.c.Wrap { // read multicodec header.
		if err := mc.ConsumeHeader(c.r, c.c.Header()); err != nil {
			return err
		}
	}

	// get next header, to select codec
	hdr, err := mc.ReadHeader(c.r)
	if err != nil {
		return err
	}

	// "unwind" the read as subc consumes header
	r := mc.WrapHeaderReader(hdr, c.r)

	subc := CodecWithHeader(hdr, c.c.Codecs)
	if subc == nil {
		return fmt.Errorf("no codec for %s", hdr)
	}

	c.c.Last = subc
	return subc.Decoder(r).Decode(v)
}