diff --git a/go.mod b/go.mod index b4250a5..c7067a5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/jsonschema-go v0.4.3 github.com/gorilla/websocket v1.5.3 github.com/jwetzell/artnet-go v0.2.2 - github.com/jwetzell/free-d-go v0.1.1 + github.com/jwetzell/free-d-go v0.2.0 github.com/jwetzell/osc-go v0.3.0 github.com/jwetzell/psn-go v0.3.0 github.com/nats-io/nats-server/v2 v2.14.0 diff --git a/go.sum b/go.sum index 342f76c..1a1f90c 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4= github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y= github.com/jwetzell/artnet-go v0.2.2 h1:vaXSmRrSlEdETPZ/gvw6aAmVqzQm0i+gfAwyIQkVsB0= github.com/jwetzell/artnet-go v0.2.2/go.mod h1:gli97Z32a0kMkZ6taoTiK7/lqHcF/dhiGjGJdx/PxqA= -github.com/jwetzell/free-d-go v0.1.1 h1:pzY2c4qRxKFBZ2jO3z512ysvUI0BUmgd4mSlWPiFVRM= -github.com/jwetzell/free-d-go v0.1.1/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw= +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/osc-go v0.3.0 h1:z75TxuQSEmdcmZ56OAepkDa3m88SdZh//3m4nBb/XZI= github.com/jwetzell/osc-go v0.3.0/go.mod h1:kCs329JxY6Qjga08tRQ/Gl0PqhgQzLIMpOhm6uszvIc= github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY= diff --git a/internal/common/common.go b/internal/common/common.go index a1f4e7e..efd068e 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -89,7 +89,7 @@ func GetAnyAsByteSlice(value any) ([]byte, bool) { // check for a slice v := reflect.ValueOf(value) - if v.Kind() != reflect.Slice { + if v.Kind() != reflect.Slice && v.Kind() != reflect.Array { return nil, false } @@ -108,7 +108,7 @@ func GetAnyAsByteSlice(value any) ([]byte, bool) { func GetAnyAsIntSlice(value any) ([]int, bool) { - // already a []byte + // already a []int intSlice, ok := value.([]int) if ok { return intSlice, true @@ -116,7 +116,7 @@ func GetAnyAsIntSlice(value any) ([]int, bool) { // check for a slice v := reflect.ValueOf(value) - if v.Kind() != reflect.Slice { + if v.Kind() != reflect.Slice && v.Kind() != reflect.Array { return nil, false } diff --git a/internal/processor/free-d-decode.go b/internal/processor/free-d-decode.go index be23147..18f8464 100644 --- a/internal/processor/free-d-decode.go +++ b/internal/processor/free-d-decode.go @@ -21,6 +21,7 @@ func init() { type FreeDDecode struct { config config.ProcessorConfig + buf [29]byte } func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { @@ -32,7 +33,14 @@ func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.Wrappe return wrappedPayload, errors.New("freed.decode processor only accepts a []byte") } - payloadMessage, err := freeD.Decode(payloadBytes) + if len(payloadBytes) != 29 { + wrappedPayload.End = true + return wrappedPayload, errors.New("freeD packet must be exactly 29 bytes") + } + + copy(fd.buf[:], payloadBytes) + + payloadMessage, err := freeD.Decode(fd.buf) if err != nil { wrappedPayload.End = true return wrappedPayload, err diff --git a/internal/processor/test/free-d-decode_test.go b/internal/processor/test/free-d-decode_test.go index 717a344..e9e6797 100644 --- a/internal/processor/test/free-d-decode_test.go +++ b/internal/processor/test/free-d-decode_test.go @@ -34,12 +34,12 @@ func TestGoodFreeDDecode(t *testing.T) { tests := []struct { name string - payload []byte + payload [29]byte expected any }{ { name: "basic freed", - payload: []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff, + payload: [29]byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff, 0xc0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00, 50, }, expected: freeD.FreeDPosition{ diff --git a/internal/processor/test/free-d-encode_test.go b/internal/processor/test/free-d-encode_test.go index bd12b3f..7c861c5 100644 --- a/internal/processor/test/free-d-encode_test.go +++ b/internal/processor/test/free-d-encode_test.go @@ -34,12 +34,12 @@ func TestGoodFreeDEncode(t *testing.T) { tests := []struct { name string - expected []byte + expected [29]byte payload any }{ { name: "basic freed", - expected: []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff, + expected: [29]byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff, 0xc0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00, 50, }, payload: freeD.FreeDPosition{