mirror of
https://github.com/onyx-and-iris/q3rcon.git
synced 2025-01-18 10:40:47 +00:00
Request now uses reusable buffer
This commit is contained in:
parent
7d787324a7
commit
b20bca0c77
@ -1,16 +1,23 @@
|
|||||||
package packet
|
package packet
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
const bufSz = 512
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
magic []byte
|
magic []byte
|
||||||
password string
|
password string
|
||||||
|
buf *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRequest(password string) Request {
|
func NewRequest(password string) Request {
|
||||||
return Request{
|
return Request{
|
||||||
magic: []byte{'\xff', '\xff', '\xff', '\xff'},
|
magic: []byte{'\xff', '\xff', '\xff', '\xff'},
|
||||||
password: password,
|
password: password,
|
||||||
|
buf: bytes.NewBuffer(make([]byte, bufSz)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +26,8 @@ func (r Request) Header() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r Request) Encode(cmd string) []byte {
|
func (r Request) Encode(cmd string) []byte {
|
||||||
datagram := r.Header()
|
r.buf.Reset()
|
||||||
datagram = append(datagram, fmt.Sprintf(" %s %s", r.password, cmd)...)
|
r.buf.Write(r.Header())
|
||||||
return datagram
|
r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd))
|
||||||
|
return r.buf.Bytes()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user