update osc-go to v0.4.0

This commit is contained in:
Joel Wetzell
2026-09-10 08:41:49 -05:00
parent 171f006d18
commit bddca05cde
8 changed files with 55 additions and 55 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ require (
github.com/jackc/pgx/v5 v5.11.0 github.com/jackc/pgx/v5 v5.11.0
github.com/jwetzell/artnet-go v0.3.0 github.com/jwetzell/artnet-go v0.3.0
github.com/jwetzell/free-d-go v0.2.0 github.com/jwetzell/free-d-go v0.2.0
github.com/jwetzell/osc-go v0.3.1 github.com/jwetzell/osc-go v0.4.0
github.com/jwetzell/psn-go v0.3.0 github.com/jwetzell/psn-go v0.3.0
github.com/nats-io/nats-server/v2 v2.14.6 github.com/nats-io/nats-server/v2 v2.14.6
github.com/nats-io/nats.go v1.53.1 github.com/nats-io/nats.go v1.53.1
+2 -2
View File
@@ -53,8 +53,8 @@ github.com/jwetzell/artnet-go v0.3.0 h1:MDHElOSbpgmIbYGHO9SoxsT7ynrYtV5/UHGT82ge
github.com/jwetzell/artnet-go v0.3.0/go.mod h1:zqRsSsrd6rPwJacwscPteDqGIqevjZ3Z6dpp092VJ1w= github.com/jwetzell/artnet-go v0.3.0/go.mod h1:zqRsSsrd6rPwJacwscPteDqGIqevjZ3Z6dpp092VJ1w=
github.com/jwetzell/free-d-go v0.2.0 h1:8WQW4du8Sf3d18aUzk9n5jZtHE6WdDQHDFjkFffvycc= github.com/jwetzell/free-d-go v0.2.0 h1:8WQW4du8Sf3d18aUzk9n5jZtHE6WdDQHDFjkFffvycc=
github.com/jwetzell/free-d-go v0.2.0/go.mod h1:yHuRy51NeDfN26eJ6wzZgys8qyQiS7hkYILw8yF+UJ4= github.com/jwetzell/free-d-go v0.2.0/go.mod h1:yHuRy51NeDfN26eJ6wzZgys8qyQiS7hkYILw8yF+UJ4=
github.com/jwetzell/osc-go v0.3.1 h1:IyXCUxzMFjiUFOeqOpz57zNv5D3Zf9yEYs2tKmPQnxA= github.com/jwetzell/osc-go v0.4.0 h1:TCh67SBt7cNE/6SUEzUNl9gh3iAPpbmob4KgzJOApPw=
github.com/jwetzell/osc-go v0.3.1/go.mod h1:vdfsVQ0fvtaOVwnvaz7IJ0gqtx2bLcswsVU9k7h2UGo= github.com/jwetzell/osc-go v0.4.0/go.mod h1:+2prTtm8arSLJvopFQabuHroqGcDH0rFIuSgTqciMe0=
github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY= github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY=
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o= github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8= github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8=
+24 -24
View File
@@ -60,7 +60,7 @@ func init() {
argStrings, err := params.GetStringSlice("args") argStrings, err := params.GetStringSlice("args")
if err != nil { if err != nil {
if errors.Is(err, config.ErrParamNotFound) { if errors.Is(err, config.ErrParamNotFound) {
return &OSCMessageCreate{config: processorConfig, Address: addressTemplate}, nil return &MessageCreate{config: processorConfig, Address: addressTemplate}, nil
} else { } else {
return nil, fmt.Errorf("osc.message.create args error: %w", err) return nil, fmt.Errorf("osc.message.create args error: %w", err)
} }
@@ -86,19 +86,19 @@ func init() {
} }
argTemplates = append(argTemplates, argTemplate) 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 config config.ProcessorConfig
Address *template.Template Address *template.Template
Args []*template.Template Args []*template.Template
Types string 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 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 '/'") return wrappedPayload, errors.New("osc.message.create address must start with '/'")
} }
payloadMessage := &osc.OSCMessage{ payloadMessage := &osc.Message{
Address: addressString, Address: addressString,
} }
args := []osc.OSCArg{} args := []osc.Arg{}
for argIndex, argTemplate := range omc.Args { for argIndex, argTemplate := range omc.Args {
var argBuffer bytes.Buffer var argBuffer bytes.Buffer
@@ -157,83 +157,83 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.
return wrappedPayload, nil return wrappedPayload, nil
} }
func (omc *OSCMessageCreate) Id() string { func (omc *MessageCreate) Id() string {
return omc.config.Id return omc.config.Id
} }
func (omc *OSCMessageCreate) Type() string { func (omc *MessageCreate) Type() string {
return omc.config.Type return omc.config.Type
} }
func argToTypedArg(rawArg string, oscType byte) (osc.OSCArg, error) { func argToTypedArg(rawArg string, oscType byte) (osc.Arg, error) {
switch oscType { switch oscType {
case 's': case 's':
return osc.OSCArg{ return osc.Arg{
Value: rawArg, Value: rawArg,
Type: "s", Type: "s",
}, nil }, nil
case 'i': case 'i':
number, err := strconv.ParseInt(rawArg, 10, 32) number, err := strconv.ParseInt(rawArg, 10, 32)
if err != nil { if err != nil {
return osc.OSCArg{}, err return osc.Arg{}, err
} }
return osc.OSCArg{ return osc.Arg{
Value: int32(number), Value: int32(number),
Type: "i", Type: "i",
}, nil }, nil
case 'f': case 'f':
number, err := strconv.ParseFloat(rawArg, 32) number, err := strconv.ParseFloat(rawArg, 32)
if err != nil { if err != nil {
return osc.OSCArg{}, err return osc.Arg{}, err
} }
return osc.OSCArg{ return osc.Arg{
Value: float32(number), Value: float32(number),
Type: "f", Type: "f",
}, nil }, nil
case 'b': case 'b':
data, err := hex.DecodeString(rawArg) data, err := hex.DecodeString(rawArg)
if err != nil { if err != nil {
return osc.OSCArg{}, err return osc.Arg{}, err
} }
return osc.OSCArg{ return osc.Arg{
Value: data, Value: data,
Type: "b", Type: "b",
}, nil }, nil
case 'h': case 'h':
number, err := strconv.ParseInt(rawArg, 10, 64) number, err := strconv.ParseInt(rawArg, 10, 64)
if err != nil { if err != nil {
return osc.OSCArg{}, err return osc.Arg{}, err
} }
return osc.OSCArg{ return osc.Arg{
Value: int64(number), Value: int64(number),
Type: "h", Type: "h",
}, nil }, nil
case 'd': case 'd':
number, err := strconv.ParseFloat(rawArg, 64) number, err := strconv.ParseFloat(rawArg, 64)
if err != nil { if err != nil {
return osc.OSCArg{}, err return osc.Arg{}, err
} }
return osc.OSCArg{ return osc.Arg{
Value: float64(number), Value: float64(number),
Type: "d", Type: "d",
}, nil }, nil
case 'T': case 'T':
return osc.OSCArg{ return osc.Arg{
Value: true, Value: true,
Type: "T", Type: "T",
}, nil }, nil
case 'F': case 'F':
return osc.OSCArg{ return osc.Arg{
Value: false, Value: false,
Type: "F", Type: "F",
}, nil }, nil
case 'N': case 'N':
return osc.OSCArg{ return osc.Arg{
Value: nil, Value: nil,
Type: "N", Type: "N",
}, nil }, nil
default: 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)
} }
} }
+1 -1
View File
@@ -26,7 +26,7 @@ func init() {
func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload payload := wrappedPayload.Payload
payloadMessage, ok := common.GetAnyAs[*osc.OSCMessage](payload) payloadMessage, ok := common.GetAnyAs[*osc.Message](payload)
if !ok { if !ok {
wrappedPayload.End = true wrappedPayload.End = true
+1 -1
View File
@@ -66,7 +66,7 @@ func TestGoodJsonEncode(t *testing.T) {
}{ }{
{ {
name: "basic struct", name: "basic struct",
payload: osc.OSCMessage{ payload: osc.Message{
Address: "/hello", Address: "/hello",
}, },
expected: []byte("{\"address\":\"/hello\",\"args\":null}"), expected: []byte("{\"address\":\"/hello\",\"args\":null}"),
@@ -49,8 +49,8 @@ func TestGoodOSCMessageCreate(t *testing.T) {
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
}, },
payload: osc.OSCMessage{}, payload: osc.Message{},
expected: &osc.OSCMessage{Address: "/test"}, expected: &osc.Message{Address: "/test"},
}, },
{ {
name: "address with template and no args", name: "address with template and no args",
@@ -58,7 +58,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
}, },
payload: map[string]any{"Value": "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", name: "address with template and string arg",
@@ -68,7 +68,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "s", "types": "s",
}, },
payload: map[string]any{"Value": "value"}, 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", name: "address with template and mixed args",
@@ -78,9 +78,9 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "sif", "types": "sif",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
expected: &osc.OSCMessage{ expected: &osc.Message{
Address: "/test/value", Address: "/test/value",
Args: []osc.OSCArg{ Args: []osc.Arg{
{Value: "arg1", Type: "s"}, {Value: "arg1", Type: "s"},
{Value: int32(42), Type: "i"}, {Value: int32(42), Type: "i"},
{Value: float32(3.14), Type: "f"}, {Value: float32(3.14), Type: "f"},
@@ -95,7 +95,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "h", "types": "h",
}, },
payload: map[string]any{"Value": "value"}, 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", name: "address with template and double arg",
@@ -105,7 +105,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "d", "types": "d",
}, },
payload: map[string]any{"Value": "value"}, 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", name: "address with template and true arg",
@@ -115,7 +115,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "T", "types": "T",
}, },
payload: map[string]any{"Value": "value"}, 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", name: "address with template and false arg",
@@ -125,7 +125,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "F", "types": "F",
}, },
payload: map[string]any{"Value": "value"}, 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", name: "address with template and nil arg",
@@ -135,7 +135,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "N", "types": "N",
}, },
payload: map[string]any{"Value": "value"}, 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", name: "blob arg",
@@ -145,7 +145,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
"types": "b", "types": "b",
}, },
payload: "", 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 return
} }
gotMessage, ok := got.Payload.(*osc.OSCMessage) gotMessage, ok := got.Payload.(*osc.Message)
if !ok { if !ok {
t.Fatalf("osc.message.create returned a %T payload: %+v", got, got) t.Fatalf("osc.message.create returned a %T payload: %+v", got, got)
} }
@@ -39,22 +39,22 @@ func TestGoodOSCMessageDecode(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
payload []byte payload []byte
expected *osc.OSCMessage expected *osc.Message
}{ }{
{ {
name: "basic OSC message", name: "basic OSC message",
payload: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0}, payload: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0},
expected: &osc.OSCMessage{ expected: &osc.Message{
Address: "/test", Address: "/test",
Args: []osc.OSCArg{}, Args: []osc.Arg{},
}, },
}, },
{ {
name: "basic OSC message with argument", name: "basic OSC message with argument",
payload: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 105, 0, 0, 0, 0, 0, 42}, 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", Address: "/test",
Args: []osc.OSCArg{ Args: []osc.Arg{
{ {
Type: "i", Type: "i",
Value: int32(42), Value: int32(42),
@@ -72,7 +72,7 @@ func TestGoodOSCMessageDecode(t *testing.T) {
t.Fatalf("osc.message.decode processing failed: %s", err) t.Fatalf("osc.message.decode processing failed: %s", err)
} }
gotMessage, ok := got.Payload.(*osc.OSCMessage) gotMessage, ok := got.Payload.(*osc.Message)
if !ok { if !ok {
t.Fatalf("osc.message.decode returned a %T payload: %+v", got, got) 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", name: "basic OSC message",
payload: &osc.OSCMessage{ payload: &osc.Message{
Address: "/test", Address: "/test",
}, },
expected: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0}, expected: []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 0, 0, 0},
}, },
{ {
name: "basic OSC message with argument", name: "basic OSC message with argument",
payload: &osc.OSCMessage{ payload: &osc.Message{
Address: "/test", Address: "/test",
Args: []osc.OSCArg{ Args: []osc.Arg{
{ {
Type: "i", Type: "i",
Value: int32(42), Value: int32(42),
@@ -96,9 +96,9 @@ func TestBadOSCMessageEncode(t *testing.T) {
}, },
{ {
name: "invalid OSC message argument", name: "invalid OSC message argument",
payload: &osc.OSCMessage{ payload: &osc.Message{
Address: "test", Address: "test",
Args: []osc.OSCArg{}, Args: []osc.Arg{},
}, },
errorString: "osc.message.encode processor failed to encode OSCMessage: OSC Message address must start with /", 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) { func BenchmarkOSCMessageEncode(b *testing.B) {
processorInstance := processor.OSCMessageEncode{} processorInstance := processor.OSCMessageEncode{}
payload := &osc.OSCMessage{ payload := &osc.Message{
Address: "/test", Address: "/test",
Args: []osc.OSCArg{ Args: []osc.Arg{
{ {
Type: "i", Type: "i",
Value: int32(42), Value: int32(42),