diff --git a/q3rcon.go b/q3rcon.go index ca287c6..05bf60a 100644 --- a/q3rcon.go +++ b/q3rcon.go @@ -14,12 +14,12 @@ import ( const respBufSiz = 2048 type encoder interface { - Encode(cmd string) ([]byte, error) + encode(cmd string) ([]byte, error) } type decoder interface { - IsValid(buf []byte) bool - Decode(buf []byte) string + isValid(buf []byte) bool + decode(buf []byte) string } type Rcon struct { @@ -101,7 +101,7 @@ func (r Rcon) Send(cmdWithArgs string) (string, error) { go r.listen(timeout, respChan, errChan) - encodedCmd, err := r.request.Encode(cmdWithArgs) + encodedCmd, err := r.request.encode(cmdWithArgs) if err != nil { return "", fmt.Errorf("error encoding command: %w", err) } @@ -153,8 +153,8 @@ func (r Rcon) listen(timeout time.Duration, respChan chan<- string, errChan chan } } - if r.response.IsValid(respBuf[:rlen]) { - sb.WriteString(r.response.Decode(respBuf[:rlen])) + if r.response.isValid(respBuf[:rlen]) { + sb.WriteString(r.response.decode(respBuf[:rlen])) } } } diff --git a/request.go b/request.go index 331e148..fea54ec 100644 --- a/request.go +++ b/request.go @@ -23,7 +23,7 @@ func newRequest(password string) request { } } -func (r request) Encode(cmd string) ([]byte, error) { +func (r request) encode(cmd string) ([]byte, error) { if cmd == "" { return nil, errors.New("command cannot be empty") } diff --git a/response.go b/response.go index 1c4f452..7087049 100644 --- a/response.go +++ b/response.go @@ -12,10 +12,10 @@ func newResponse() response { return response{} } -func (r response) IsValid(buf []byte) bool { +func (r response) isValid(buf []byte) bool { return len(buf) > len(responseHeader) && bytes.HasPrefix(buf, []byte(responseHeader)) } -func (r response) Decode(buf []byte) string { +func (r response) decode(buf []byte) string { return string(buf[len(responseHeader):]) }