示例#1
0
文件: conn.go 项目: yzl11/vessel
func readPayloads(r io.Reader) ([][]byte, error) {
	nBytesExpecting, err := iohelper.ReadInt32(r)
	if err != nil {
		return nil, err
	}

	if nBytesExpecting > 0 {
		buf, err := iohelper.ReadN(r, nBytesExpecting)

		if err != nil && err == io.EOF {
			return nil, err
		}

		payloads := processMessage(buf)

		if len(payloads) > 0 {
			return payloads, err
		}
	}
	return nil, errors.New("unexcepted payload")
}
示例#2
0
文件: conn.go 项目: qgweb/go-hbase
func readPayloads(r io.Reader) ([][]byte, error) {
	nBytesExpecting, err := iohelper.ReadInt32(r)
	if err != nil {
		return nil, errors.Trace(err)
	}

	if nBytesExpecting > 0 {
		buf, err := iohelper.ReadN(r, nBytesExpecting)
		// Question: why should we return error only when we get an io.EOF error?
		if err != nil && ErrorEqual(err, io.EOF) {
			return nil, errors.Trace(err)
		}

		payloads, err := processMessage(buf)
		if err != nil {
			return nil, errors.Trace(err)
		}

		if len(payloads) > 0 {
			return payloads, nil
		}
	}
	return nil, errors.New("unexpected payload")
}