mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-08-17 21:03:56 +00:00
just use marshal methods directly
This commit is contained in:
@@ -56,11 +56,35 @@ func Decode(bytes []byte) (ArtNetPacket, error) {
|
||||
opCode := binary.LittleEndian.Uint16(bytes[8:10])
|
||||
switch opCode {
|
||||
case OpPoll:
|
||||
return NewArtPoll(bytes)
|
||||
artPoll := ArtPoll{}
|
||||
|
||||
err := artPoll.UnmarshalBinary(bytes)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &artPoll, nil
|
||||
case OpDmx:
|
||||
return NewArtDmx(bytes)
|
||||
artDmx := ArtDmx{}
|
||||
|
||||
err := artDmx.UnmarshalBinary(bytes)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &artDmx, nil
|
||||
case OpTimeCode:
|
||||
return NewArtTimeCode(bytes)
|
||||
artTimeCode := ArtTimeCode{}
|
||||
|
||||
err := artTimeCode.UnmarshalBinary(bytes)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &artTimeCode, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unhandled opcode: %#x", opCode)
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@ type ArtDmx struct {
|
||||
Data []uint8
|
||||
}
|
||||
|
||||
func NewArtDmx(data []byte) (*ArtDmx, error) {
|
||||
artDmx := ArtDmx{}
|
||||
|
||||
err := artDmx.UnmarshalBinary(data)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &artDmx, nil
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) GetOpCode() uint16 {
|
||||
return ad.OpCode
|
||||
}
|
||||
|
||||
+3
-1
@@ -30,7 +30,9 @@ func TestGoodArtDmx(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
got, err := artnet.NewArtDmx(test.Data)
|
||||
got := artnet.ArtDmx{}
|
||||
|
||||
err := got.UnmarshalBinary(test.Data)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to decode ArtDmx: %s", err)
|
||||
|
||||
@@ -23,18 +23,6 @@ type ArtPoll struct {
|
||||
OemLo uint8
|
||||
}
|
||||
|
||||
func NewArtPoll(data []byte) (*ArtPoll, error) {
|
||||
artPoll := ArtPoll{}
|
||||
|
||||
err := artPoll.UnmarshalBinary(data)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &artPoll, nil
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) GetOpCode() uint16 {
|
||||
return ap.OpCode
|
||||
}
|
||||
|
||||
-12
@@ -20,18 +20,6 @@ type ArtTimeCode struct {
|
||||
Type uint8
|
||||
}
|
||||
|
||||
func NewArtTimeCode(data []byte) (*ArtTimeCode, error) {
|
||||
artTimeCode := ArtTimeCode{}
|
||||
|
||||
err := artTimeCode.UnmarshalBinary(data)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &artTimeCode, nil
|
||||
}
|
||||
|
||||
func (atc *ArtTimeCode) GetOpCode() uint16 {
|
||||
return atc.OpCode
|
||||
}
|
||||
|
||||
+3
-1
@@ -31,7 +31,9 @@ func TestGoodArtTimeCode(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
got, err := artnet.NewArtTimeCode(test.Data)
|
||||
got := artnet.ArtTimeCode{}
|
||||
|
||||
err := got.UnmarshalBinary(test.Data)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to decode ArtTimeCode: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user