mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-08-19 21:23:57 +00:00
update free-d-decode
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user