switch to unmarshal marshal

This commit is contained in:
Joel Wetzell
2025-12-23 14:10:31 -06:00
parent 4326f99776
commit 5097901aa9
6 changed files with 143 additions and 135 deletions
+5 -29
View File
@@ -1,37 +1,13 @@
package artnet
import (
"encoding/binary"
"errors"
"slices"
"encoding"
)
type ArtNetPacket interface {
encoding.BinaryUnmarshaler
encoding.BinaryMarshaler
GetOpCode() uint16
}
var ArtNetID []uint8 = []uint8{'A', 'r', 't', '-', 'N', 'e', 't', 0x00}
type ArtNetHeader struct {
ID []uint8
OpCode uint16
ProtVerHi uint8
ProtVerLo uint8
}
func NewHeader(data []byte) (*ArtNetHeader, error) {
if len(data) < 12 {
return nil, errors.New("header must be at least 12 bytes")
}
if !slices.Equal(ArtNetID, data[0:8]) {
return nil, errors.New("header id does not match Art-Net ID")
}
return &ArtNetHeader{
OpCode: binary.LittleEndian.Uint16(data[8:10]),
ProtVerHi: data[10],
ProtVerLo: data[11],
}, nil
GetProtVer() uint16
GetID() []uint8
}