mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-09-10 15:39:25 +00:00
update osc-go to v0.4.0
This commit is contained in:
@@ -60,7 +60,7 @@ func init() {
|
||||
argStrings, err := params.GetStringSlice("args")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
return &OSCMessageCreate{config: processorConfig, Address: addressTemplate}, nil
|
||||
return &MessageCreate{config: processorConfig, Address: addressTemplate}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("osc.message.create args error: %w", err)
|
||||
}
|
||||
@@ -86,19 +86,19 @@ func init() {
|
||||
}
|
||||
argTemplates = append(argTemplates, argTemplate)
|
||||
}
|
||||
return &OSCMessageCreate{config: processorConfig, Address: addressTemplate, Args: argTemplates, Types: typesString}, nil
|
||||
return &MessageCreate{config: processorConfig, Address: addressTemplate, Args: argTemplates, Types: typesString}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type OSCMessageCreate struct {
|
||||
type MessageCreate struct {
|
||||
config config.ProcessorConfig
|
||||
Address *template.Template
|
||||
Args []*template.Template
|
||||
Types string
|
||||
}
|
||||
|
||||
func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
func (omc *MessageCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
|
||||
templateData := wrappedPayload
|
||||
|
||||
@@ -122,11 +122,11 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.
|
||||
return wrappedPayload, errors.New("osc.message.create address must start with '/'")
|
||||
}
|
||||
|
||||
payloadMessage := &osc.OSCMessage{
|
||||
payloadMessage := &osc.Message{
|
||||
Address: addressString,
|
||||
}
|
||||
|
||||
args := []osc.OSCArg{}
|
||||
args := []osc.Arg{}
|
||||
|
||||
for argIndex, argTemplate := range omc.Args {
|
||||
var argBuffer bytes.Buffer
|
||||
@@ -157,83 +157,83 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (omc *OSCMessageCreate) Id() string {
|
||||
func (omc *MessageCreate) Id() string {
|
||||
return omc.config.Id
|
||||
}
|
||||
|
||||
func (omc *OSCMessageCreate) Type() string {
|
||||
func (omc *MessageCreate) Type() string {
|
||||
return omc.config.Type
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType byte) (osc.OSCArg, error) {
|
||||
func argToTypedArg(rawArg string, oscType byte) (osc.Arg, error) {
|
||||
|
||||
switch oscType {
|
||||
case 's':
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: rawArg,
|
||||
Type: "s",
|
||||
}, nil
|
||||
case 'i':
|
||||
number, err := strconv.ParseInt(rawArg, 10, 32)
|
||||
if err != nil {
|
||||
return osc.OSCArg{}, err
|
||||
return osc.Arg{}, err
|
||||
}
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: int32(number),
|
||||
Type: "i",
|
||||
}, nil
|
||||
case 'f':
|
||||
number, err := strconv.ParseFloat(rawArg, 32)
|
||||
if err != nil {
|
||||
return osc.OSCArg{}, err
|
||||
return osc.Arg{}, err
|
||||
}
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: float32(number),
|
||||
Type: "f",
|
||||
}, nil
|
||||
case 'b':
|
||||
data, err := hex.DecodeString(rawArg)
|
||||
if err != nil {
|
||||
return osc.OSCArg{}, err
|
||||
return osc.Arg{}, err
|
||||
}
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: data,
|
||||
Type: "b",
|
||||
}, nil
|
||||
case 'h':
|
||||
number, err := strconv.ParseInt(rawArg, 10, 64)
|
||||
if err != nil {
|
||||
return osc.OSCArg{}, err
|
||||
return osc.Arg{}, err
|
||||
}
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: int64(number),
|
||||
Type: "h",
|
||||
}, nil
|
||||
case 'd':
|
||||
number, err := strconv.ParseFloat(rawArg, 64)
|
||||
if err != nil {
|
||||
return osc.OSCArg{}, err
|
||||
return osc.Arg{}, err
|
||||
}
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: float64(number),
|
||||
Type: "d",
|
||||
}, nil
|
||||
case 'T':
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: true,
|
||||
Type: "T",
|
||||
}, nil
|
||||
case 'F':
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: false,
|
||||
Type: "F",
|
||||
}, nil
|
||||
case 'N':
|
||||
return osc.OSCArg{
|
||||
return osc.Arg{
|
||||
Value: nil,
|
||||
Type: "N",
|
||||
}, nil
|
||||
default:
|
||||
return osc.OSCArg{}, fmt.Errorf("osc.message.create unhandled osc type: %c", oscType)
|
||||
return osc.Arg{}, fmt.Errorf("osc.message.create unhandled osc type: %c", oscType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func init() {
|
||||
|
||||
func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
payload := wrappedPayload.Payload
|
||||
payloadMessage, ok := common.GetAnyAs[*osc.OSCMessage](payload)
|
||||
payloadMessage, ok := common.GetAnyAs[*osc.Message](payload)
|
||||
|
||||
if !ok {
|
||||
wrappedPayload.End = true
|
||||
|
||||
@@ -66,7 +66,7 @@ func TestGoodJsonEncode(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "basic struct",
|
||||
payload: osc.OSCMessage{
|
||||
payload: osc.Message{
|
||||
Address: "/hello",
|
||||
},
|
||||
expected: []byte("{\"address\":\"/hello\",\"args\":null}"),
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
params: map[string]any{
|
||||
"address": "/test",
|
||||
},
|
||||
payload: osc.OSCMessage{},
|
||||
expected: &osc.OSCMessage{Address: "/test"},
|
||||
payload: osc.Message{},
|
||||
expected: &osc.Message{Address: "/test"},
|
||||
},
|
||||
{
|
||||
name: "address with template and no args",
|
||||
@@ -58,7 +58,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"address": "/test/{{.Payload.Value}}",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value"},
|
||||
expected: &osc.Message{Address: "/test/value"},
|
||||
},
|
||||
{
|
||||
name: "address with template and string arg",
|
||||
@@ -68,7 +68,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "s",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value", Args: []osc.OSCArg{{Value: "arg1", Type: "s"}}},
|
||||
expected: &osc.Message{Address: "/test/value", Args: []osc.Arg{{Value: "arg1", Type: "s"}}},
|
||||
},
|
||||
{
|
||||
name: "address with template and mixed args",
|
||||
@@ -78,9 +78,9 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "sif",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{
|
||||
expected: &osc.Message{
|
||||
Address: "/test/value",
|
||||
Args: []osc.OSCArg{
|
||||
Args: []osc.Arg{
|
||||
{Value: "arg1", Type: "s"},
|
||||
{Value: int32(42), Type: "i"},
|
||||
{Value: float32(3.14), Type: "f"},
|
||||
@@ -95,7 +95,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "h",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value", Args: []osc.OSCArg{{Value: int64(42), Type: "h"}}},
|
||||
expected: &osc.Message{Address: "/test/value", Args: []osc.Arg{{Value: int64(42), Type: "h"}}},
|
||||
},
|
||||
{
|
||||
name: "address with template and double arg",
|
||||
@@ -105,7 +105,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "d",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value", Args: []osc.OSCArg{{Value: float64(42), Type: "d"}}},
|
||||
expected: &osc.Message{Address: "/test/value", Args: []osc.Arg{{Value: float64(42), Type: "d"}}},
|
||||
},
|
||||
{
|
||||
name: "address with template and true arg",
|
||||
@@ -115,7 +115,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "T",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value", Args: []osc.OSCArg{{Value: true, Type: "T"}}},
|
||||
expected: &osc.Message{Address: "/test/value", Args: []osc.Arg{{Value: true, Type: "T"}}},
|
||||
},
|
||||
{
|
||||
name: "address with template and false arg",
|
||||
@@ -125,7 +125,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "F",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value", Args: []osc.OSCArg{{Value: false, Type: "F"}}},
|
||||
expected: &osc.Message{Address: "/test/value", Args: []osc.Arg{{Value: false, Type: "F"}}},
|
||||
},
|
||||
{
|
||||
name: "address with template and nil arg",
|
||||
@@ -135,7 +135,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "N",
|
||||
},
|
||||
payload: map[string]any{"Value": "value"},
|
||||
expected: &osc.OSCMessage{Address: "/test/value", Args: []osc.OSCArg{{Value: nil, Type: "N"}}},
|
||||
expected: &osc.Message{Address: "/test/value", Args: []osc.Arg{{Value: nil, Type: "N"}}},
|
||||
},
|
||||
{
|
||||
name: "blob arg",
|
||||
@@ -145,7 +145,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
"types": "b",
|
||||
},
|
||||
payload: "",
|
||||
expected: &osc.OSCMessage{Address: "/test", Args: []osc.OSCArg{{Value: []byte{0xde, 0xad, 0xbe, 0xef}, Type: "b"}}},
|
||||
expected: &osc.Message{Address: "/test", Args: []osc.Arg{{Value: []byte{0xde, 0xad, 0xbe, 0xef}, Type: "b"}}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
gotMessage, ok := got.Payload.(*osc.OSCMessage)
|
||||
gotMessage, ok := got.Payload.(*osc.Message)
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.create returned a %T payload: %+v", got, got)
|
||||
}
|
||||
|
||||
@@ -39,22 +39,22 @@ func TestGoodOSCMessageDecode(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
payload []byte
|
||||
expected *osc.OSCMessage
|
||||
expected *osc.Message
|
||||
}{
|
||||
{
|
||||
name: "basic OSC message",
|
||||
payload: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0},
|
||||
expected: &osc.OSCMessage{
|
||||
expected: &osc.Message{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{},
|
||||
Args: []osc.Arg{},
|
||||
},
|
||||
},
|
||||
{
|
||||
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.Message{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{
|
||||
Args: []osc.Arg{
|
||||
{
|
||||
Type: "i",
|
||||
Value: int32(42),
|
||||
@@ -72,7 +72,7 @@ func TestGoodOSCMessageDecode(t *testing.T) {
|
||||
t.Fatalf("osc.message.decode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotMessage, ok := got.Payload.(*osc.OSCMessage)
|
||||
gotMessage, ok := got.Payload.(*osc.Message)
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.decode returned a %T payload: %+v", got, got)
|
||||
}
|
||||
|
||||
@@ -43,16 +43,16 @@ func TestGoodOSCMessageEncode(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "basic OSC message",
|
||||
payload: &osc.OSCMessage{
|
||||
payload: &osc.Message{
|
||||
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.Message{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{
|
||||
Args: []osc.Arg{
|
||||
{
|
||||
Type: "i",
|
||||
Value: int32(42),
|
||||
@@ -96,9 +96,9 @@ func TestBadOSCMessageEncode(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "invalid OSC message argument",
|
||||
payload: &osc.OSCMessage{
|
||||
payload: &osc.Message{
|
||||
Address: "test",
|
||||
Args: []osc.OSCArg{},
|
||||
Args: []osc.Arg{},
|
||||
},
|
||||
errorString: "osc.message.encode processor failed to encode OSCMessage: OSC Message address must start with /",
|
||||
},
|
||||
@@ -120,9 +120,9 @@ func TestBadOSCMessageEncode(t *testing.T) {
|
||||
|
||||
func BenchmarkOSCMessageEncode(b *testing.B) {
|
||||
processorInstance := processor.OSCMessageEncode{}
|
||||
payload := &osc.OSCMessage{
|
||||
payload := &osc.Message{
|
||||
Address: "/test",
|
||||
Args: []osc.OSCArg{
|
||||
Args: []osc.Arg{
|
||||
{
|
||||
Type: "i",
|
||||
Value: int32(42),
|
||||
|
||||
Reference in New Issue
Block a user