From c6f3cc8b88129c9f0224f802920aa7f6ce7202f6 Mon Sep 17 00:00:00 2001 From: Kevin Golding Date: Tue, 14 Jan 2020 08:22:09 +0000 Subject: [PATCH] add BinStr() helper --- examples/cli/main.go | 7 +------ helpers.go | 10 ++++++++++ pocsagencode_test.go | 9 --------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/examples/cli/main.go b/examples/cli/main.go index 390260c..92dfa3b 100644 --- a/examples/cli/main.go +++ b/examples/cli/main.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "strconv" - "strings" pc "github.com/kgolding/go-pocsagencode" ) @@ -27,11 +26,7 @@ func main() { } burst, _ := pc.Generate(messages) - binStrs := []string{} - for _, b := range burst.Bytes() { - binStrs = append(binStrs, fmt.Sprintf("0b%b", b)) - } fmt.Printf("Message: %s\n\n", burst.String()) fmt.Printf("Hex bytes: % X\n\n", burst.Bytes()) - fmt.Printf("Binary: %s\n\n", strings.Join(binStrs, ", ")) + fmt.Printf("Binary: %s\n\n", burst.BinStr()) } diff --git a/helpers.go b/helpers.go index 8fe19bd..8277d63 100644 --- a/helpers.go +++ b/helpers.go @@ -3,6 +3,7 @@ package pocsagencode import ( "encoding/binary" "fmt" + "strings" ) type Burst []uint32 @@ -38,3 +39,12 @@ func (b Burst) Bytes() []byte { } return buf } + +// BinStr returns a binary string split into bytes +func (b Burst) BinStr() string { + binStrs := []string{} + for _, b := range b.Bytes() { + binStrs = append(binStrs, fmt.Sprintf("0b%b", b)) + } + return strings.Join(binStrs, ", ") +} diff --git a/pocsagencode_test.go b/pocsagencode_test.go index 3f44f23..b09548b 100644 --- a/pocsagencode_test.go +++ b/pocsagencode_test.go @@ -1,8 +1,6 @@ package pocsagencode import ( - "fmt" - "strings" "testing" ) @@ -35,11 +33,4 @@ func Test_Encode(t *testing.T) { } } } - t.Log(enc) - t.Log(enc.Bytes()) - binStrs := []string{} - for _, b := range enc.Bytes() { - binStrs = append(binStrs, fmt.Sprintf("0b%b", b)) - } - t.Log(strings.Join(binStrs, ", ")) }