From 48ec7908dd829aee34bca611cf311d33d0fb0a51 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sun, 18 May 2025 19:31:56 -0500 Subject: [PATCH] switch to using the actual osc library here --- cmd/makeosc/makeosc.go | 67 ++++++++++++++++++++++++----------- cmd/receiveosc/receiveosc.go | 4 +-- cmd/sendosc/sendosc.go | 68 ++++++++++++++++++++++++++---------- go.mod | 6 +--- go.sum | 4 --- 5 files changed, 99 insertions(+), 50 deletions(-) diff --git a/cmd/makeosc/makeosc.go b/cmd/makeosc/makeosc.go index e4a15a7..0bbc130 100644 --- a/cmd/makeosc/makeosc.go +++ b/cmd/makeosc/makeosc.go @@ -6,8 +6,7 @@ import ( "os" "strconv" - "github.com/hypebeast/go-osc/osc" - + osc "github.com/jwetzell/osc-go" "github.com/spf13/cobra" ) @@ -31,55 +30,84 @@ func main() { rootCmd.Execute() } -func argToTypedArg(rawArg string, oscType string) any { +func argToTypedArg(rawArg string, oscType string) osc.OSCArg { + switch oscType { case "s": - return rawArg + return osc.OSCArg{ + Value: rawArg, + Type: "s", + } case "i": number, err := strconv.ParseInt(rawArg, 10, 32) if err != nil { // ... handle error panic(err) } - return int32(number) + return osc.OSCArg{ + Value: int32(number), + Type: "i", + } case "f": number, err := strconv.ParseFloat(rawArg, 32) if err != nil { // ... handle error panic(err) } - return float32(number) + return osc.OSCArg{ + Value: float32(number), + Type: "f", + } case "b": data, err := hex.DecodeString(rawArg) if err != nil { // ... handle error panic(err) } - return data + return osc.OSCArg{ + Value: data, + Type: "b", + } case "h": number, err := strconv.ParseInt(rawArg, 10, 64) if err != nil { // ... handle error panic(err) } - return int64(number) + return osc.OSCArg{ + Value: int64(number), + Type: "h", + } case "d": number, err := strconv.ParseFloat(rawArg, 64) if err != nil { // ... handle error panic(err) } - return float64(number) + return osc.OSCArg{ + Value: float64(number), + Type: "d", + } case "T": - return true + return osc.OSCArg{ + Value: true, + Type: "T", + } case "F": - return false + return osc.OSCArg{ + Value: false, + Type: "F", + } case "N": - return nil + return osc.OSCArg{ + Value: nil, + Type: "N", + } default: fmt.Print("unhandled osc type: ") fmt.Printf("%s.\n", oscType) - return rawArg + // TODO(jwetzell): something better than this like actual nil, err thing + return osc.OSCArg{} } } @@ -107,7 +135,10 @@ func slipEncode(bytes []byte) []byte { func make(address string, args []string, types []string, slip bool) { - oscMessage := osc.NewMessage(address) + oscMessage := osc.OSCMessage{ + Address: address, + Args: []osc.OSCArg{}, + } for index, arg := range args { oscType := "s" @@ -115,14 +146,10 @@ func make(address string, args []string, types []string, slip bool) { oscType = types[index] } - oscMessage.Append(argToTypedArg(arg, oscType)) + oscMessage.Args = append(oscMessage.Args, argToTypedArg(arg, oscType)) } - oscMessageBuffer, err := oscMessage.MarshalBinary() - - if err != nil { - panic(err) - } + oscMessageBuffer := oscMessage.ToBytes() if slip { oscMessageBuffer = slipEncode(oscMessageBuffer) diff --git a/cmd/receiveosc/receiveosc.go b/cmd/receiveosc/receiveosc.go index 5c5c923..94291b2 100644 --- a/cmd/receiveosc/receiveosc.go +++ b/cmd/receiveosc/receiveosc.go @@ -4,7 +4,7 @@ import ( "fmt" "net" - "github.com/chabad360/go-osc/osc" + osc "github.com/jwetzell/osc-go" "github.com/spf13/cobra" ) @@ -50,7 +50,7 @@ func listen(netAddress string) { panic(err) } - oscMessage, err := osc.NewMessageFromData(buffer[0:bytesRead]) + oscMessage, err := osc.MessageFromBytes(buffer[0:bytesRead]) if err != nil { panic(err) diff --git a/cmd/sendosc/sendosc.go b/cmd/sendosc/sendosc.go index 3390eba..dd4d6df 100644 --- a/cmd/sendosc/sendosc.go +++ b/cmd/sendosc/sendosc.go @@ -6,7 +6,7 @@ import ( "net" "strconv" - "github.com/hypebeast/go-osc/osc" + osc "github.com/jwetzell/osc-go" "github.com/spf13/cobra" ) @@ -39,55 +39,84 @@ func main() { rootCmd.Execute() } -func argToTypedArg(rawArg string, oscType string) any { +func argToTypedArg(rawArg string, oscType string) osc.OSCArg { + switch oscType { case "s": - return rawArg + return osc.OSCArg{ + Value: rawArg, + Type: "s", + } case "i": number, err := strconv.ParseInt(rawArg, 10, 32) if err != nil { // ... handle error panic(err) } - return int32(number) + return osc.OSCArg{ + Value: int32(number), + Type: "i", + } case "f": number, err := strconv.ParseFloat(rawArg, 32) if err != nil { // ... handle error panic(err) } - return float32(number) + return osc.OSCArg{ + Value: float32(number), + Type: "f", + } case "b": data, err := hex.DecodeString(rawArg) if err != nil { // ... handle error panic(err) } - return data + return osc.OSCArg{ + Value: data, + Type: "b", + } case "h": number, err := strconv.ParseInt(rawArg, 10, 64) if err != nil { // ... handle error panic(err) } - return int64(number) + return osc.OSCArg{ + Value: int64(number), + Type: "h", + } case "d": number, err := strconv.ParseFloat(rawArg, 64) if err != nil { // ... handle error panic(err) } - return float64(number) + return osc.OSCArg{ + Value: float64(number), + Type: "d", + } case "T": - return true + return osc.OSCArg{ + Value: true, + Type: "T", + } case "F": - return false + return osc.OSCArg{ + Value: false, + Type: "F", + } case "N": - return nil + return osc.OSCArg{ + Value: nil, + Type: "N", + } default: fmt.Print("unhandled osc type: ") fmt.Printf("%s.\n", oscType) - return rawArg + // TODO(jwetzell): something better than this like actual nil, err thing + return osc.OSCArg{} } } @@ -115,22 +144,23 @@ func slipEncode(bytes []byte) []byte { func send(host string, port int32, address string, args []string, types []string, protocol string, slip bool) { - oscMessage := osc.NewMessage(address) + oscMessage := osc.OSCMessage{ + Address: address, + Args: []osc.OSCArg{}, + } for index, arg := range args { oscType := "s" if len(types) > index { oscType = types[index] } + arg := argToTypedArg(arg, oscType) + + oscMessage.Args = append(oscMessage.Args, arg) - oscMessage.Append(argToTypedArg(arg, oscType)) } - oscMessageBuffer, err := oscMessage.MarshalBinary() - - if err != nil { - panic(err) - } + oscMessageBuffer := oscMessage.ToBytes() if slip { oscMessageBuffer = slipEncode(oscMessageBuffer) diff --git a/go.mod b/go.mod index 12dc099..5676d56 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,7 @@ module github.com/jwetzell/osc-go go 1.23.1 -require ( - github.com/chabad360/go-osc v0.0.0-20220502185613-216f362cdf0a - github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5 - github.com/spf13/cobra v1.8.1 -) +require github.com/spf13/cobra v1.8.1 require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index 8ca32c0..912390a 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,4 @@ -github.com/chabad360/go-osc v0.0.0-20220502185613-216f362cdf0a h1:MTor/GgULww+hISVbeiNuC5vyT1mc2xa6/14ib0lvyc= -github.com/chabad360/go-osc v0.0.0-20220502185613-216f362cdf0a/go.mod h1:/aAn5LNn+s7zq33XItIcYLr6aOntVkWckHPAG40yeUc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5 h1:fqwINudmUrvGCuw+e3tedZ2UJ0hklSw6t8UPomctKyQ= -github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5/go.mod h1:lqMjoCs0y0GoRRujSPZRBaGb4c5ER6TfkFKSClxkMbY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=