From 24de71c46433ad574951b04202a8ca8d6e215d08 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 13 Jul 2020 08:05:15 +0200 Subject: [PATCH] rename consts --- conn-client.go | 10 +++++----- conn-server.go | 10 +++++----- header.go | 14 +++++++------- interleaved-frame.go | 4 ++-- request.go | 19 ++++++++++--------- response.go | 7 ++++--- utils.go | 7 +++---- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/conn-client.go b/conn-client.go index 935e2e9d..e932c395 100644 --- a/conn-client.go +++ b/conn-client.go @@ -13,8 +13,8 @@ import ( ) const ( - _CLIENT_READ_BUFFER_SIZE = 4096 - _CLIENT_WRITE_BUFFER_SIZE = 4096 + clientReadBufferSize = 4096 + clientWriteBufferSize = 4096 ) // ConnClientConf allows to configure a ConnClient. @@ -52,8 +52,8 @@ func NewConnClient(conf ConnClientConf) (*ConnClient, error) { return &ConnClient{ conf: conf, - br: bufio.NewReaderSize(conf.Conn, _CLIENT_READ_BUFFER_SIZE), - bw: bufio.NewWriterSize(conf.Conn, _CLIENT_WRITE_BUFFER_SIZE), + br: bufio.NewReaderSize(conf.Conn, clientReadBufferSize), + bw: bufio.NewWriterSize(conf.Conn, clientWriteBufferSize), }, nil } @@ -75,7 +75,7 @@ func (c *ConnClient) readFrameOrResponse(frame *InterleavedFrame) (interface{}, } c.br.UnreadByte() - if b == _INTERLEAVED_FRAME_MAGIC { + if b == interleavedFrameMagicByte { err := frame.read(c.br) if err != nil { return nil, err diff --git a/conn-server.go b/conn-server.go index 0d94d5cc..4dcd2311 100644 --- a/conn-server.go +++ b/conn-server.go @@ -7,8 +7,8 @@ import ( ) const ( - _SERVER_READ_BUFFER_SIZE = 4096 - _SERVER_WRITE_BUFFER_SIZE = 4096 + serverReadBufferSize = 4096 + serverWriteBufferSize = 4096 ) // ConnServerConf allows to configure a ConnServer. @@ -43,8 +43,8 @@ func NewConnServer(conf ConnServerConf) *ConnServer { return &ConnServer{ conf: conf, - br: bufio.NewReaderSize(conf.Conn, _SERVER_READ_BUFFER_SIZE), - bw: bufio.NewWriterSize(conf.Conn, _SERVER_WRITE_BUFFER_SIZE), + br: bufio.NewReaderSize(conf.Conn, serverReadBufferSize), + bw: bufio.NewWriterSize(conf.Conn, serverWriteBufferSize), } } @@ -68,7 +68,7 @@ func (s *ConnServer) ReadFrameOrRequest(frame *InterleavedFrame) (interface{}, e } s.br.UnreadByte() - if b == _INTERLEAVED_FRAME_MAGIC { + if b == interleavedFrameMagicByte { err := frame.read(s.br) if err != nil { return nil, err diff --git a/header.go b/header.go index bd9bc04f..2a9a1843 100644 --- a/header.go +++ b/header.go @@ -9,9 +9,9 @@ import ( ) const ( - _MAX_HEADER_COUNT = 255 - _MAX_HEADER_KEY_LENGTH = 1024 - _MAX_HEADER_VALUE_LENGTH = 1024 + headerMaxEntryCount = 255 + headerMaxKeyLength = 1024 + headerMaxValueLength = 1024 ) func headerKeyNormalize(in string) string { @@ -49,12 +49,12 @@ func headerRead(rb *bufio.Reader) (Header, error) { break } - if len(h) >= _MAX_HEADER_COUNT { - return nil, fmt.Errorf("headers count exceeds %d", _MAX_HEADER_COUNT) + if len(h) >= headerMaxEntryCount { + return nil, fmt.Errorf("headers count exceeds %d", headerMaxEntryCount) } key := string([]byte{byt}) - byts, err := readBytesLimited(rb, ':', _MAX_HEADER_KEY_LENGTH-1) + byts, err := readBytesLimited(rb, ':', headerMaxKeyLength-1) if err != nil { return nil, err } @@ -75,7 +75,7 @@ func headerRead(rb *bufio.Reader) (Header, error) { } rb.UnreadByte() - byts, err = readBytesLimited(rb, '\r', _MAX_HEADER_VALUE_LENGTH) + byts, err = readBytesLimited(rb, '\r', headerMaxValueLength) if err != nil { return nil, err } diff --git a/interleaved-frame.go b/interleaved-frame.go index 6a5db9d4..e31d3c7d 100644 --- a/interleaved-frame.go +++ b/interleaved-frame.go @@ -8,7 +8,7 @@ import ( ) const ( - _INTERLEAVED_FRAME_MAGIC = 0x24 + interleavedFrameMagicByte = 0x24 ) // StreamType is the type of a stream. @@ -52,7 +52,7 @@ func (f *InterleavedFrame) read(r io.Reader) error { return err } - if header[0] != _INTERLEAVED_FRAME_MAGIC { + if header[0] != interleavedFrameMagicByte { return fmt.Errorf("wrong magic byte (0x%.2x)", header[0]) } diff --git a/request.go b/request.go index e7823ec0..b8746ace 100644 --- a/request.go +++ b/request.go @@ -7,9 +7,10 @@ import ( ) const ( - _MAX_METHOD_LENGTH = 128 - _MAX_PATH_LENGTH = 1024 - _MAX_PROTOCOL_LENGTH = 128 + rtspProtocol10 = "RTSP/1.0" + requestMaxLethodLength = 128 + requestMaxPathLength = 1024 + requestMaxProtocolLength = 128 ) // Method is a RTSP request method. @@ -48,7 +49,7 @@ type Request struct { func readRequest(rb *bufio.Reader) (*Request, error) { req := &Request{} - byts, err := readBytesLimited(rb, ' ', _MAX_METHOD_LENGTH) + byts, err := readBytesLimited(rb, ' ', requestMaxLethodLength) if err != nil { return nil, err } @@ -58,7 +59,7 @@ func readRequest(rb *bufio.Reader) (*Request, error) { return nil, fmt.Errorf("empty method") } - byts, err = readBytesLimited(rb, ' ', _MAX_PATH_LENGTH) + byts, err = readBytesLimited(rb, ' ', requestMaxPathLength) if err != nil { return nil, err } @@ -78,14 +79,14 @@ func readRequest(rb *bufio.Reader) (*Request, error) { return nil, fmt.Errorf("invalid url scheme '%s'", req.Url.Scheme) } - byts, err = readBytesLimited(rb, '\r', _MAX_PROTOCOL_LENGTH) + byts, err = readBytesLimited(rb, '\r', requestMaxProtocolLength) if err != nil { return nil, err } proto := string(byts[:len(byts)-1]) - if proto != _RTSP_PROTO { - return nil, fmt.Errorf("expected '%s', got '%s'", _RTSP_PROTO, proto) + if proto != rtspProtocol10 { + return nil, fmt.Errorf("expected '%s', got '%s'", rtspProtocol10, proto) } err = readByteEqual(rb, '\n') @@ -115,7 +116,7 @@ func (req *Request) write(bw *bufio.Writer) error { RawQuery: req.Url.RawQuery, } - _, err := bw.Write([]byte(string(req.Method) + " " + u.String() + " " + _RTSP_PROTO + "\r\n")) + _, err := bw.Write([]byte(string(req.Method) + " " + u.String() + " " + rtspProtocol10 + "\r\n")) if err != nil { return err } diff --git a/response.go b/response.go index ac06cce7..53199289 100644 --- a/response.go +++ b/response.go @@ -10,6 +10,7 @@ import ( type StatusCode int const ( + // standard status codes StatusContinue StatusCode = 100 StatusOK StatusCode = 200 StatusMovedPermanently StatusCode = 301 @@ -140,8 +141,8 @@ func readResponse(rb *bufio.Reader) (*Response, error) { } proto := string(byts[:len(byts)-1]) - if proto != _RTSP_PROTO { - return nil, fmt.Errorf("expected '%s', got '%s'", _RTSP_PROTO, proto) + if proto != rtspProtocol10 { + return nil, fmt.Errorf("expected '%s', got '%s'", rtspProtocol10, proto) } byts, err = readBytesLimited(rb, ' ', 4) @@ -191,7 +192,7 @@ func (res *Response) write(bw *bufio.Writer) error { } } - _, err := bw.Write([]byte(_RTSP_PROTO + " " + strconv.FormatInt(int64(res.StatusCode), 10) + " " + res.StatusMessage + "\r\n")) + _, err := bw.Write([]byte(rtspProtocol10 + " " + strconv.FormatInt(int64(res.StatusCode), 10) + " " + res.StatusMessage + "\r\n")) if err != nil { return err } diff --git a/utils.go b/utils.go index a862a795..b147a402 100644 --- a/utils.go +++ b/utils.go @@ -8,8 +8,7 @@ import ( ) const ( - _RTSP_PROTO = "RTSP/1.0" - _MAX_CONTENT_LENGTH = 4096 + rtspMaxContentLength = 4096 ) func readBytesLimited(rb *bufio.Reader, delim byte, n int) ([]byte, error) { @@ -51,8 +50,8 @@ func readContent(rb *bufio.Reader, header Header) ([]byte, error) { return nil, fmt.Errorf("invalid Content-Length") } - if cl > _MAX_CONTENT_LENGTH { - return nil, fmt.Errorf("Content-Length exceeds %d", _MAX_CONTENT_LENGTH) + if cl > rtspMaxContentLength { + return nil, fmt.Errorf("Content-Length exceeds %d", rtspMaxContentLength) } ret := make([]byte, cl)