protocol/rtsp: simplified ReadResponse further by using only one sscanf

This commit is contained in:
Saxon 2019-04-28 13:23:35 +09:30
parent 9abcfb138b
commit fa7c3044f3
1 changed files with 4 additions and 13 deletions

View File

@ -135,21 +135,12 @@ func ReadResponse(r io.Reader) (*Response, error) {
return nil, errSmallResponse return nil, errSmallResponse
} }
// Check that it was terminated by CRLF. if s[:5] != "RTSP/" {
if s[len(s)-2] != '\r' { return nil, errors.New("not a valid RTSP response")
return nil, errors.New("line not terminated by CRLF")
} }
resp.Proto = "RTSP"
var proto string _, err = fmt.Sscanf(s[5:12], "%d.%d %d %s", &resp.ProtoMajor, &resp.ProtoMinor, &resp.StatusCode)
_, err = fmt.Sscanf(s, "%s %d %s", &proto, &resp.StatusCode, &resp.Status)
if err != nil {
return nil, err
}
s1 := strings.Split(proto, "/")
resp.Proto = s1[0]
_, err = fmt.Sscanf(s1[1], "%d.%d", &resp.ProtoMajor, &resp.ProtoMinor)
if err != nil { if err != nil {
return nil, err return nil, err
} }