diff --git a/internal/processor/json-encode.go b/internal/processor/json-encode.go new file mode 100644 index 0000000..5036a39 --- /dev/null +++ b/internal/processor/json-encode.go @@ -0,0 +1,38 @@ +package processor + +import ( + "bytes" + "context" + "encoding/json" + + "github.com/jwetzell/showbridge-go/internal/config" +) + +type JsonEncode struct { + config config.ProcessorConfig +} + +func (je *JsonEncode) Process(ctx context.Context, payload any) (any, error) { + var payloadBuffer bytes.Buffer + + err := json.NewEncoder(&payloadBuffer).Encode(payload) + + if err != nil { + return nil, err + } + + return payloadBuffer.Bytes(), nil +} + +func (je *JsonEncode) Type() string { + return je.config.Type +} + +func init() { + RegisterProcessor(ProcessorRegistration{ + Type: "json.encode", + New: func(config config.ProcessorConfig) (Processor, error) { + return &JsonEncode{config: config}, nil + }, + }) +}