update free-d-decode

This commit is contained in:
Joel Wetzell
2026-05-23 07:57:34 -05:00
parent 4323a21015
commit 5a2aefbdd5
6 changed files with 19 additions and 11 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+3 -3
View File
@@ -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
}
+9 -1
View File
@@ -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
@@ -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{
@@ -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{