remove internal packages, move everything into q3rcon

{request}.buf initialised with 0 length.

encoder, decoder interfaces added.
This commit is contained in:
2026-02-19 00:22:32 +00:00
parent caffd65cb3
commit 3f45588afb
6 changed files with 105 additions and 80 deletions

35
request.go Normal file
View File

@@ -0,0 +1,35 @@
package q3rcon
import (
"bytes"
"errors"
"fmt"
)
const (
bufSz = 1024
requestHeader = "\xff\xff\xff\xffrcon"
)
type request struct {
password string
buf *bytes.Buffer
}
func newRequest(password string) request {
return request{
password: password,
buf: bytes.NewBuffer(make([]byte, 0, bufSz)),
}
}
func (r request) Encode(cmd string) ([]byte, error) {
if cmd == "" {
return nil, errors.New("command cannot be empty")
}
r.buf.Reset()
r.buf.WriteString(requestHeader)
r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd))
return r.buf.Bytes(), nil
}