mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
upgrade osc library and switch to pointers
This commit is contained in:
@@ -3,6 +3,7 @@ package processor
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
@@ -29,7 +30,7 @@ func (omd *OSCMessageDecode) Process(ctx context.Context, payload any) (any, err
|
||||
|
||||
message, err := osc.MessageFromBytes(payloadBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("osc.message.decode processor failed to decode OSC message: %w", err)
|
||||
}
|
||||
return message, nil
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ type OSCMessageEncode struct {
|
||||
}
|
||||
|
||||
func (ome *OSCMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
||||
payloadMessage, ok := GetAnyAs[osc.OSCMessage](payload)
|
||||
payloadMessage, ok := GetAnyAs[*osc.OSCMessage](payload)
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("osc.message.encode processor only accepts an OSCMessage")
|
||||
return nil, errors.New("osc.message.encode processor only accepts an *OSCMessage")
|
||||
}
|
||||
|
||||
bytes := payloadMessage.ToBytes()
|
||||
|
||||
@@ -33,12 +33,12 @@ func TestGoodOSCMessageDecode(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
payload []byte
|
||||
expected osc.OSCMessage
|
||||
expected *osc.OSCMessage
|
||||
}{
|
||||
{
|
||||
name: "basic OSC message",
|
||||
payload: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0},
|
||||
expected: osc.OSCMessage{
|
||||
expected: &osc.OSCMessage{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{},
|
||||
},
|
||||
@@ -46,7 +46,7 @@ func TestGoodOSCMessageDecode(t *testing.T) {
|
||||
{
|
||||
name: "basic OSC message with argument",
|
||||
payload: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 105, 0, 0, 0, 0, 0, 42},
|
||||
expected: osc.OSCMessage{
|
||||
expected: &osc.OSCMessage{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{
|
||||
{
|
||||
@@ -66,7 +66,7 @@ func TestGoodOSCMessageDecode(t *testing.T) {
|
||||
t.Fatalf("osc.message.decode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotMessage, ok := got.(osc.OSCMessage)
|
||||
gotMessage, ok := got.(*osc.OSCMessage)
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.decode returned a %T payload: %s", got, got)
|
||||
}
|
||||
@@ -100,6 +100,11 @@ func TestBadOSCMessageDecode(t *testing.T) {
|
||||
payload: []byte{48, 116, 101, 115, 116, 0, 0, 0, 44, 105, 0, 0, 0, 0, 0, 42},
|
||||
errorString: "osc.message.decode processor needs an OSC looking []byte",
|
||||
},
|
||||
{
|
||||
name: "invalid OSC payload",
|
||||
payload: []byte{47, 116, 101, 115, 116, 0},
|
||||
errorString: "osc.message.decode processor failed to decode OSC message: string data is not properly padded",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
@@ -37,14 +37,14 @@ func TestGoodOSCMessageEncode(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "basic OSC message",
|
||||
payload: osc.OSCMessage{
|
||||
payload: &osc.OSCMessage{
|
||||
Address: "/test",
|
||||
},
|
||||
expected: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0},
|
||||
},
|
||||
{
|
||||
name: "basic OSC message with argument",
|
||||
payload: osc.OSCMessage{
|
||||
payload: &osc.OSCMessage{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{
|
||||
{
|
||||
@@ -86,7 +86,7 @@ func TestBadOSCMessageEncode(t *testing.T) {
|
||||
{
|
||||
name: "non-osc message input",
|
||||
payload: "test",
|
||||
errorString: "osc.message.encode processor only accepts an OSCMessage",
|
||||
errorString: "osc.message.encode processor only accepts an *OSCMessage",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user