rename consts

This commit is contained in:
aler9
2020-07-13 08:05:15 +02:00
parent d94a3e94ed
commit 24de71c464
7 changed files with 36 additions and 35 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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])
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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)