mirror of https://bitbucket.org/ausocean/av.git
protocol/rtsp: simplified ReadResponse further by using only one sscanf
This commit is contained in:
parent
9abcfb138b
commit
fa7c3044f3
|
@ -135,21 +135,12 @@ func ReadResponse(r io.Reader) (*Response, error) {
|
|||
return nil, errSmallResponse
|
||||
}
|
||||
|
||||
// Check that it was terminated by CRLF.
|
||||
if s[len(s)-2] != '\r' {
|
||||
return nil, errors.New("line not terminated by CRLF")
|
||||
if s[:5] != "RTSP/" {
|
||||
return nil, errors.New("not a valid RTSP response")
|
||||
}
|
||||
resp.Proto = "RTSP"
|
||||
|
||||
var proto string
|
||||
_, 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)
|
||||
_, err = fmt.Sscanf(s[5:12], "%d.%d %d %s", &resp.ProtoMajor, &resp.ProtoMinor, &resp.StatusCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue