示例#1
0
func (c *decoder) Decode(v interface{}) error {
	pbv, ok := v.(proto.Message)
	if !ok {
		return ErrNotProtobuf
	}

	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 {
		msg, err := msgio.NewReader(c.r).ReadMsg()
		if err != nil {
			return err
		}
		return proto.Unmarshal(msg, pbv)
	}

	return errors.New("protobuf without msgio not supported yet")
}
示例#2
0
文件: rw.go 项目: tilgovi/go-libp2p
// NewETMReader Encrypt-Then-MAC
func NewETMReader(r io.Reader, s cipher.Stream, mac HMAC) msgio.ReadCloser {
	return &etmReader{msg: msgio.NewReader(r), str: s, mac: mac}
}