mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
41 lines
807 B
Go
41 lines
807 B
Go
package processor
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
freeD "github.com/jwetzell/free-d-go"
|
|
"github.com/jwetzell/showbridge-go/internal/config"
|
|
)
|
|
|
|
type FreeDDecode struct {
|
|
config config.ProcessorConfig
|
|
}
|
|
|
|
func (fdd *FreeDDecode) Process(ctx context.Context, payload any) (any, error) {
|
|
payloadBytes, ok := GetAnyAs[[]byte](payload)
|
|
|
|
if !ok {
|
|
return nil, errors.New("freed.decode processor only accepts a []byte")
|
|
}
|
|
|
|
payloadMessage, err := freeD.Decode(payloadBytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return payloadMessage, nil
|
|
}
|
|
|
|
func (fdd *FreeDDecode) Type() string {
|
|
return fdd.config.Type
|
|
}
|
|
|
|
func init() {
|
|
RegisterProcessor(ProcessorRegistration{
|
|
Type: "freed.decode",
|
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
return &FreeDDecode{config: config}, nil
|
|
},
|
|
})
|
|
}
|