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") }
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") }