add free-d encode and decode

This commit is contained in:
Joel Wetzell
2025-11-30 10:35:18 -05:00
parent ed6f6d5759
commit 500a3be136
4 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package processing
import (
"context"
"fmt"
"log/slog"
freeD "github.com/jwetzell/free-d-go"
)
type FreeDDecode struct {
config ProcessorConfig
}
func (fdd *FreeDDecode) Process(ctx context.Context, payload any) (any, error) {
payloadBytes, ok := payload.([]byte)
if !ok {
return nil, fmt.Errorf("freed.decode processor only accepts a []byte")
}
payloadMessage, err := freeD.Decode(payloadBytes)
if err != nil {
slog.Error("error decoding", "err", err)
}
return payloadMessage, nil
}
func (fdd *FreeDDecode) Type() string {
return fdd.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "freed.decode",
New: func(config ProcessorConfig) (Processor, error) {
return &FreeDDecode{config: config}, nil
},
})
}

View File

@@ -0,0 +1,36 @@
package processing
import (
"context"
"fmt"
freeD "github.com/jwetzell/free-d-go"
)
type FreeDEncode struct {
config ProcessorConfig
}
func (fde *FreeDEncode) Process(ctx context.Context, payload any) (any, error) {
payloadPosition, ok := payload.(freeD.FreeDPosition)
if !ok {
return nil, fmt.Errorf("freed.decode processor only accepts a FreeDEncode")
}
payloadBytes := freeD.Encode(payloadPosition)
return payloadBytes, nil
}
func (fde *FreeDEncode) Type() string {
return fde.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "freed.encode",
New: func(config ProcessorConfig) (Processor, error) {
return &FreeDEncode{config: config}, nil
},
})
}