From: Jeff Halter Date: Sun, 9 Jun 2024 02:26:14 +0000 (-0700) Subject: Replace custom slice concat func with slices.Concat X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/9c44621ee1ca9abfca79c593e80193afd9204c83?hp=9a75b7cbfa6fa37ed10732bbff8b722d652a1cdc Replace custom slice concat func with slices.Concat --- diff --git a/concat/slices.go b/concat/slices.go deleted file mode 100644 index 88b9fae..0000000 --- a/concat/slices.go +++ /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 -} diff --git a/hotline/field.go b/hotline/field.go index 4d2962b..c205c42 100644 --- a/hotline/field.go +++ b/hotline/field.go @@ -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 { diff --git a/hotline/file_header.go b/hotline/file_header.go index 60c652e..61b8e28 100644 --- a/hotline/file_header.go +++ b/hotline/file_header.go @@ -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, diff --git a/hotline/server.go b/hotline/server.go index aca2221..78b7a37 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -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, } diff --git a/hotline/transaction.go b/hotline/transaction.go index b01fdfb..d9bbc22 100644 --- a/hotline/transaction.go +++ b/hotline/transaction.go @@ -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,