mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
38 lines
846 B
Go
38 lines
846 B
Go
package processor
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
"github.com/jwetzell/showbridge-go/internal/common"
|
|
"github.com/jwetzell/showbridge-go/internal/config"
|
|
)
|
|
|
|
type MQTTMessageEncode struct {
|
|
config config.ProcessorConfig
|
|
}
|
|
|
|
func (mme *MQTTMessageEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
payloadMessage, ok := common.GetAnyAs[mqtt.Message](payload)
|
|
|
|
if !ok {
|
|
return nil, errors.New("mqtt.message.encode processor only accepts an mqtt.Message")
|
|
}
|
|
|
|
return payloadMessage.Payload(), nil
|
|
}
|
|
|
|
func (mme *MQTTMessageEncode) Type() string {
|
|
return mme.config.Type
|
|
}
|
|
|
|
func init() {
|
|
RegisterProcessor(ProcessorRegistration{
|
|
Type: "mqtt.message.encode",
|
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
return &MQTTMessageEncode{config: config}, nil
|
|
},
|
|
})
|
|
}
|