switch to fixed size array

This commit is contained in:
Joel Wetzell
2026-05-23 07:41:42 -05:00
parent e8b3869048
commit acb6708b80
3 changed files with 28 additions and 25 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ import (
func main() {
messageBytes := []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff,
messageBytes := [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,
}
+7 -1
View File
@@ -28,7 +28,13 @@ func main() {
if err != nil {
slog.Error("error reading from UDP", "err", err)
} else if length > 0 {
message, err := freeD.Decode(buffer[0:length])
if length != 29 {
slog.Warn("received UDP packet with unexpected length", "length", length)
continue
}
var messageBytes [29]byte
copy(messageBytes[:], buffer[0:length])
message, err := freeD.Decode(messageBytes)
if err != nil {
slog.Error("error decoding", "err", err)
}