]> git.r.bdr.sh - rbdr/mobius/commitdiff
Replace custom slice concat func with slices.Concat
authorJeff Halter <redacted>
Sun, 9 Jun 2024 02:26:14 +0000 (19:26 -0700)
committerJeff Halter <redacted>
Sun, 9 Jun 2024 21:05:15 +0000 (14:05 -0700)
concat/slices.go [deleted file]
hotline/field.go
hotline/file_header.go
hotline/server.go
hotline/transaction.go

diff --git a/concat/slices.go b/concat/slices.go
deleted file mode 100644 (file)
index 88b9fae..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-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
-}
index 4d2962bb3930c2dbce7dd3660150c3f52ec27a24..c205c42b8f2eb5eb43eb45e7d8714ab0c493e920 100644 (file)
@@ -2,7 +2,7 @@ package hotline
 
 import (
        "encoding/binary"
-       "github.com/jhalter/mobius/concat"
+       "slices"
 )
 
 // List of Hotline protocol field types taken from the official 1.9 protocol document
@@ -91,7 +91,7 @@ func NewField(id uint16, data []byte) Field {
 }
 
 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 {
index 60c652e36eb5cf1be776b192ed5bdc822cc71315..61b8e288f4a8d79fb3ee3d42d51b43f9a993c08a 100644 (file)
@@ -2,7 +2,7 @@ package hotline
 
 import (
        "encoding/binary"
-       "github.com/jhalter/mobius/concat"
+       "slices"
 )
 
 type FileHeader struct {
@@ -28,7 +28,7 @@ func NewFileHeader(fileName string, isDir bool) FileHeader {
 }
 
 func (fh *FileHeader) Payload() []byte {
-       return concat.Slices(
+       return slices.Concat(
                fh.Size,
                fh.Type,
                fh.FilePath,
index aca2221a1adc22676c6bf676e7f7d43f05722d53..78b7a371befa7a69041161848c91e900b678a5f4 100644 (file)
@@ -283,7 +283,7 @@ func NewServer(configDir, netInterface string, netPort int, logger *zap.SugaredL
                        for {
                                tr := &TrackerRegistration{
                                        UserCount:   server.userCount(),
-                                       PassID:      server.TrackerPassID[:],
+                                       PassID:      server.TrackerPassID,
                                        Name:        server.Config.Name,
                                        Description: server.Config.Description,
                                }
index b01fdfb112e8c6bb61922728cd0d879dabfb00e9..d9bbc22fd1f7c4c3f256434cd45b60b8bc1b3206 100644 (file)
@@ -5,8 +5,8 @@ import (
        "encoding/binary"
        "errors"
        "fmt"
-       "github.com/jhalter/mobius/concat"
        "math/rand"
+       "slices"
 )
 
 const (
@@ -203,7 +203,7 @@ func (t *Transaction) MarshalBinary() (data []byte, err error) {
                fieldPayload = append(fieldPayload, field.Payload()...)
        }
 
-       return concat.Slices(
+       return slices.Concat(
                []byte{t.Flags, t.IsReply},
                t.Type,
                t.ID,