From d4348143ade17fc5d54a94be070cf9822a1d999e Mon Sep 17 00:00:00 2001 From: d <> Date: Tue, 3 Oct 2023 11:53:11 +0200 Subject: [PATCH] ToBytes, return []byte{0,0,0,0} when string is empty --- osc.go | 4 ++-- osc_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osc.go b/osc.go index 5345af9..a36ae74 100644 --- a/osc.go +++ b/osc.go @@ -44,8 +44,8 @@ type Packet interface { // This means that the returned byte slice is padded with null bytes // so that it's length is a multiple of 4. func ToBytes(s string) []byte { - if len(s) == 0 { - return []byte{} + if s == "" { + return []byte{0, 0, 0, 0} } return Pad(append([]byte(s), 0)) } diff --git a/osc_test.go b/osc_test.go index 8bbdc7d..56ae0d2 100644 --- a/osc_test.go +++ b/osc_test.go @@ -12,7 +12,7 @@ func TestToBytes(t *testing.T) { }{ { Input: "", - Expected: []byte{}, + Expected: []byte{0, 0, 0, 0}, }, { Input: "a",