mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-09-04 21:28:57 +00:00
some byte slice cleanup
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type ArtPoll struct {
|
||||
ID []uint8
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
@@ -31,7 +31,7 @@ func (ap *ArtPoll) GetProtVer() uint16 {
|
||||
return uint16(ap.ProtVerHi)<<8 + uint16(ap.ProtVerLo)
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) GetID() []uint8 {
|
||||
func (ap *ArtPoll) GetID() [8]uint8 {
|
||||
return ap.ID
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ func (ap *ArtPoll) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtPoll packet must be at least 14 bytes long")
|
||||
}
|
||||
|
||||
ap.ID = data[0:8]
|
||||
copy(ap.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID, ap.ID) {
|
||||
if !slices.Equal(ArtNetID[:], ap.ID[:]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
@@ -59,8 +59,13 @@ func (ap *ArtPoll) UnmarshalBinary(data []byte) error {
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) MarshalBinary() ([]byte, error) {
|
||||
data := []byte(ArtNetID)
|
||||
data = append(data, byte(ap.OpCode), byte(ap.OpCode>>8), ap.ProtVerHi, ap.ProtVerLo, ap.Flags, ap.DiagPriority)
|
||||
data := make([]byte, 8+6)
|
||||
copy(data[0:8], ap.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], ap.OpCode)
|
||||
data[10] = ap.ProtVerHi
|
||||
data[11] = ap.ProtVerLo
|
||||
data[12] = ap.Flags
|
||||
data[13] = ap.DiagPriority
|
||||
//TODO(jwetzell): pack extended poll fields
|
||||
return data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user