Apply go fix modernizations

This commit is contained in:
Ian Gulliver
2026-03-05 11:39:14 -08:00
parent 9c2787a200
commit 8f83c1c8e9
4 changed files with 13 additions and 28 deletions

View File

@@ -58,7 +58,7 @@ func MulticastAddr(universe uint16) *net.UDPAddr {
}
}
func ParsePacket(data []byte) (interface{}, error) {
func ParsePacket(data []byte) (any, error) {
if len(data) < 22 {
return nil, ErrPacketTooShort
}
@@ -99,10 +99,7 @@ func parseDataPacket(data []byte) (*DataPacket, error) {
return nil, ErrPacketTooShort
}
dmxLen := int(propCount) - 1
if dmxLen > 512 {
dmxLen = 512
}
dmxLen := min(int(propCount)-1, 512)
if len(data) < 126+dmxLen {
return nil, ErrPacketTooShort
@@ -121,7 +118,7 @@ func parseDataPacket(data []byte) (*DataPacket, error) {
return pkt, nil
}
func parseExtendedPacket(data []byte) (interface{}, error) {
func parseExtendedPacket(data []byte) (any, error) {
if len(data) < 118 {
return nil, ErrPacketTooShort
}
@@ -149,7 +146,7 @@ func parseExtendedPacket(data []byte) (interface{}, error) {
universeCount := (len(data) - 120) / 2
pkt.Universes = make([]uint16, 0, universeCount)
for i := 0; i < universeCount; i++ {
for i := range universeCount {
u := binary.BigEndian.Uint16(data[120+i*2 : 122+i*2])
if u >= 1 && u <= 63999 {
pkt.Universes = append(pkt.Universes, u)
@@ -160,10 +157,7 @@ func parseExtendedPacket(data []byte) (interface{}, error) {
}
func BuildDataPacket(universe uint16, sequence uint8, sourceName string, cid [16]byte, data []byte) []byte {
dataLen := len(data)
if dataLen > 512 {
dataLen = 512
}
dataLen := min(len(data), 512)
pktLen := 126 + dataLen
buf := make([]byte, pktLen)
@@ -200,10 +194,7 @@ func BuildDataPacket(universe uint16, sequence uint8, sourceName string, cid [16
}
func BuildDiscoveryPacket(sourceName string, cid [16]byte, page, lastPage uint8, universes []uint16) []byte {
universeCount := len(universes)
if universeCount > 512 {
universeCount = 512
}
universeCount := min(len(universes), 512)
pktLen := 120 + universeCount*2
buf := make([]byte, pktLen)