add basic artnet decode/encode

This commit is contained in:
Joel Wetzell
2025-12-23 14:19:52 -06:00
parent 3c0f555a6f
commit 407f1f3618
4 changed files with 87 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
package processor
import (
"context"
"fmt"
"github.com/jwetzell/artnet-go"
"github.com/jwetzell/showbridge-go/internal/config"
)
type ArtNetDecode struct {
config config.ProcessorConfig
}
func (ad *ArtNetDecode) Process(ctx context.Context, payload any) (any, error) {
payloadBytes, ok := payload.([]byte)
if !ok {
return nil, fmt.Errorf("artnet.decode processor only accepts a []byte")
}
payloadMessage, err := artnet.Decode(payloadBytes)
if err != nil {
return nil, err
}
return payloadMessage, nil
}
func (ad *ArtNetDecode) Type() string {
return ad.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "artnet.decode",
New: func(config config.ProcessorConfig) (Processor, error) {
return &ArtNetDecode{config: config}, nil
},
})
}

View File

@@ -0,0 +1,41 @@
package processor
import (
"context"
"fmt"
"github.com/jwetzell/artnet-go"
"github.com/jwetzell/showbridge-go/internal/config"
)
type ArtNetEncode struct {
config config.ProcessorConfig
}
func (ad *ArtNetEncode) Process(ctx context.Context, payload any) (any, error) {
payloadPacket, ok := payload.(artnet.ArtNetPacket)
if !ok {
return nil, fmt.Errorf("artnet.encode processor only accepts an ArtNetPacket")
}
payloadBytes, err := payloadPacket.MarshalBinary()
if err != nil {
return nil, err
}
return payloadBytes, nil
}
func (ad *ArtNetEncode) Type() string {
return ad.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "artnet.encode",
New: func(config config.ProcessorConfig) (Processor, error) {
return &ArtNetEncode{config: config}, nil
},
})
}