func (c *decoder) Decode(v interface{}) error { var w io.Writer switch v := v.(type) { case []byte: w = &bufWriter{B: v} case io.Writer: w = v default: return mc.ErrType } if c.mc { // if multicodec, consume the header first if err := mc.ConsumeHeader(c.r, Header); err != nil { return err } } r, err := msgio.LimitedReader(c.r) if err != nil { return err } _, err = io.Copy(w, r) return err }
func (c *decoder) Decode(v interface{}) error { r := c.r if c.c.mc { // if multicodec, consume the header first if err := mc.ConsumeHeader(c.r, c.c.Header()); err != nil { return err } } if c.c.msgio { // need to make a new one per read. var err error r, err = msgio.LimitedReader(c.r) if err != nil { return err } } return json.NewDecoder(r).Decode(v) }