diff --git a/audio-linux.go b/audio-linux.go index 18a2a22..ced79d8 100644 --- a/audio-linux.go +++ b/audio-linux.go @@ -98,7 +98,7 @@ func (a *audioStruct) recLoop(deinitNeededChan, deinitFinishedChan chan bool) { } // Do not send silence frames to the radio unnecessarily - if allZero(frameBuf[:n]) { + if isAllZero(frameBuf[:n]) { continue } buf.Write(frameBuf[:n]) diff --git a/controlstream.go b/controlstream.go index 24f131d..c6ac99e 100644 --- a/controlstream.go +++ b/controlstream.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "errors" "fmt" - "strings" "time" ) @@ -129,14 +128,6 @@ func (s *controlStream) sendRequestSerialAndAudio() error { return nil } -func (s *controlStream) parseNullTerminatedString(d []byte) (res string) { - nullIndex := strings.Index(string(d), "\x00") - if nullIndex > 0 { - res = string(d[:nullIndex]) - } - return -} - func (s *controlStream) handleRead(r []byte) error { switch len(r) { case 64: @@ -207,7 +198,7 @@ func (s *controlStream) handleRead(r []byte) error { s.secondAuthTimer.Stop() s.requestSerialAndAudioTimeout.Stop() - devName := s.parseNullTerminatedString(r[64:]) + devName := parseNullTerminatedString(r[64:]) log.Print("got serial and audio request success, device name: ", devName) // Stuff can change in the meantime because of a previous login... diff --git a/util.go b/util.go index b3daa4c..e8edf36 100644 --- a/util.go +++ b/util.go @@ -1,7 +1,9 @@ package main +import "strings" + // Checks if all bytes are zeros -func allZero(s []byte) bool { +func isAllZero(s []byte) bool { for _, v := range s { if v != 0 { return false @@ -9,3 +11,11 @@ func allZero(s []byte) bool { } return true } + +func parseNullTerminatedString(d []byte) (res string) { + nullIndex := strings.Index(string(d), "\x00") + if nullIndex > 0 { + res = string(d[:nullIndex]) + } + return +}