From c05d4fe9519ee78ab58fdbd178333832f8c5dc90 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Wed, 1 Mar 2023 15:15:32 +0000 Subject: [PATCH] 4. Split converters --- internal/fusefs/converters.go | 61 +++++++++++++++++++++++++++++++++++ internal/fusefs/fuse.go | 53 ------------------------------ 2 files changed, 61 insertions(+), 53 deletions(-) create mode 100644 internal/fusefs/converters.go diff --git a/internal/fusefs/converters.go b/internal/fusefs/converters.go new file mode 100644 index 0000000..c0a5cee --- /dev/null +++ b/internal/fusefs/converters.go @@ -0,0 +1,61 @@ +package fusefs + +import ( + "go.arsenm.dev/infinitime" + "context" + "strconv" +) + +func converterU8(ctx context.Context, in <-chan uint8) <-chan []byte { + out := make(chan []byte, 2) + go func() { + for { + select { + case <- ctx.Done(): + return + case event := <-in: + out <- []byte(strconv.Itoa(int(event)) + "\n") + } + } + }() + return out +} + +func converterU32(ctx context.Context, in <-chan uint32) <-chan []byte { + out := make(chan []byte, 2) + go func() { + for { + select { + case <- ctx.Done(): + return + case event := <-in: + out <- []byte(strconv.Itoa(int(event)) + "\n") + } + } + }() + return out +} + +func converterMotionValues(ctx context.Context, in <-chan infinitime.MotionValues) <-chan []byte { + out := make(chan []byte, 2) + go func() { + for { + select { + case <- ctx.Done(): + return + case event := <-in: + out <- []byte(strconv.Itoa(int(event.X)) + " " + strconv.Itoa(int(event.Y)) + " " + strconv.Itoa(int(event.Z)) + "\n") + } + } + }() + return out +} + +func converter1String(ctx context.Context, in string) <-chan []byte { + out := make(chan []byte, 2) + out <- []byte(in + "\n") + close(out) + return out +} + + diff --git a/internal/fusefs/fuse.go b/internal/fusefs/fuse.go index feb5c03..f394c2d 100644 --- a/internal/fusefs/fuse.go +++ b/internal/fusefs/fuse.go @@ -8,63 +8,10 @@ import ( "syscall" "github.com/hanwen/go-fuse/v2/fs" "github.com/hanwen/go-fuse/v2/fuse" - "strconv" "io" "bytes" ) -func converterU8(ctx context.Context, in <-chan uint8) <-chan []byte { - out := make(chan []byte, 2) - go func() { - for { - select { - case <- ctx.Done(): - return - case event := <-in: - out <- []byte(strconv.Itoa(int(event)) + "\n") - } - } - }() - return out -} - -func converterU32(ctx context.Context, in <-chan uint32) <-chan []byte { - out := make(chan []byte, 2) - go func() { - for { - select { - case <- ctx.Done(): - return - case event := <-in: - out <- []byte(strconv.Itoa(int(event)) + "\n") - } - } - }() - return out -} - -func converterMotionValues(ctx context.Context, in <-chan infinitime.MotionValues) <-chan []byte { - out := make(chan []byte, 2) - go func() { - for { - select { - case <- ctx.Done(): - return - case event := <-in: - out <- []byte(strconv.Itoa(int(event.X)) + " " + strconv.Itoa(int(event.Y)) + " " + strconv.Itoa(int(event.Z)) + "\n") - } - } - }() - return out -} - -func converter1String(ctx context.Context, in string) <-chan []byte { - out := make(chan []byte, 2) - out <- []byte(in + "\n") - close(out) - return out -} - type ITProperty struct { name string Ino uint64