diff --git a/src/device/input/parse/v01/transform.go b/src/device/input/parse/v01/transform.go new file mode 100644 index 0000000..258deb9 --- /dev/null +++ b/src/device/input/parse/v01/transform.go @@ -0,0 +1,14 @@ +package v01 + +type ( + transformation map[string]string +) + +func (t transformation) pipe(s string) string { + for i := range s { + if v := t[s[i:i+1]]; v != "" { + s = s[:i] + v[:1] + s[i+1:] + } + } + return s +} diff --git a/src/device/input/parse/v01/v01.go b/src/device/input/parse/v01/v01.go index 916d35d..ec60583 100644 --- a/src/device/input/parse/v01/v01.go +++ b/src/device/input/parse/v01/v01.go @@ -40,10 +40,9 @@ type ( Message string } Players []struct { - Transformation v01Transformation + Transformation transformation } } - v01Transformation map[string]string ) func NewV01(ctx context.Context, src raw.Raw) *V01 { @@ -98,15 +97,6 @@ func (cfg v01Cfg) transform(msg v01Msg) v01Msg { return msg } -func (t v01Transformation) pipe(s string) string { - for i := range s { - if v := t[s[i:i+1]]; v != "" { - s = s[:i] + v[:1] + s[i+1:] - } - } - return s -} - func (v01 *V01) telemetry(msg v01Msg) { if FlagDebug { log.Printf("%s|%dms", msg.U, time.Now().UnixNano()/int64(time.Millisecond)-msg.T) diff --git a/src/device/input/parse/v01/v01_test.go b/src/device/input/parse/v01/v01_test.go index b81d3e1..c21ba70 100644 --- a/src/device/input/parse/v01/v01_test.go +++ b/src/device/input/parse/v01/v01_test.go @@ -42,7 +42,7 @@ func TestV01TransformationPipe(t *testing.T) { for name, d := range cases { c := d t.Run(name, func(t *testing.T) { - got := v01Transformation(c.xform).pipe(c.input) + got := transformation(c.xform).pipe(c.input) if got != c.want { t.Errorf("%+v(%s) want %s got %s", c.xform, c.input, c.want, got) }