+++ /dev/null
-package concat
-
-// Slices is a utility function to make appending multiple slices less painful and more efficient
-// Source: https://stackoverflow.com/questions/37884361/concat-multiple-slices-in-golang
-func Slices(slices ...[]byte) []byte {
- var totalLen int
- for _, s := range slices {
- totalLen += len(s)
- }
- tmp := make([]byte, totalLen)
- var i int
- for _, s := range slices {
- i += copy(tmp[i:], s)
- }
-
- return tmp
-}
import (
"encoding/binary"
- "github.com/jhalter/mobius/concat"
+ "slices"
)
// List of Hotline protocol field types taken from the official 1.9 protocol document
}
func (f Field) Payload() []byte {
- return concat.Slices(f.ID, f.FieldSize, f.Data)
+ return slices.Concat(f.ID, f.FieldSize, f.Data)
}
func getField(id int, fields *[]Field) *Field {
import (
"encoding/binary"
- "github.com/jhalter/mobius/concat"
+ "slices"
)
type FileHeader struct {
}
func (fh *FileHeader) Payload() []byte {
- return concat.Slices(
+ return slices.Concat(
fh.Size,
fh.Type,
fh.FilePath,
for {
tr := &TrackerRegistration{
UserCount: server.userCount(),
- PassID: server.TrackerPassID[:],
+ PassID: server.TrackerPassID,
Name: server.Config.Name,
Description: server.Config.Description,
}
"encoding/binary"
"errors"
"fmt"
- "github.com/jhalter/mobius/concat"
"math/rand"
+ "slices"
)
const (
fieldPayload = append(fieldPayload, field.Payload()...)
}
- return concat.Slices(
+ return slices.Concat(
[]byte{t.Flags, t.IsReply},
t.Type,
t.ID,