From 4f61ece4b1c98fc097c23e1f9daf87e27e37bf7d Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Thu, 4 Jan 2024 19:45:08 +0100 Subject: [PATCH] Revert "move wasm" This reverts commit 5c16e18bda994b3b3fd3dbb1f2a52df00942952d. --- {wasm => internal/wasm}/command_actions.go | 7 +++---- {wasm => internal/wasm}/imports.go | 0 {wasm => internal/wasm}/imports_stub.go | 0 internal/{ => wasm}/memory.go | 6 +++--- run.go => run/run.go | 9 +++++---- 5 files changed, 11 insertions(+), 11 deletions(-) rename {wasm => internal/wasm}/command_actions.go (90%) rename {wasm => internal/wasm}/imports.go (100%) rename {wasm => internal/wasm}/imports_stub.go (100%) rename internal/{ => wasm}/memory.go (91%) rename run.go => run/run.go (86%) diff --git a/wasm/command_actions.go b/internal/wasm/command_actions.go similarity index 90% rename from wasm/command_actions.go rename to internal/wasm/command_actions.go index 5e50602..d14d9de 100644 --- a/wasm/command_actions.go +++ b/internal/wasm/command_actions.go @@ -18,7 +18,6 @@ import ( "fmt" sdk "github.com/conduitio/conduit-processor-sdk" - "github.com/conduitio/conduit-processor-sdk/internal" "github.com/conduitio/conduit-processor-sdk/proto" ) @@ -30,7 +29,7 @@ func NextCommand() (sdk.Command, error) { // we're allocating some memory in advance, so that // we don't need to introduce another call just to // get the amount of memory which is needed. - ptr, cleanup := internal.Allocate(defaultCommandSize) + ptr, cleanup := allocate(defaultCommandSize) defer cleanup() // request Conduit to write the command to the given allocation @@ -48,7 +47,7 @@ func NextCommand() (sdk.Command, error) { } // parse the command - cmd, err := proto.UnmarshalCommand(internal.PtrToByteArray(ptr, resp)) + cmd, err := proto.UnmarshalCommand(ptrToByteArray(ptr, resp)) if err != nil { return nil, fmt.Errorf("failed unmarshalling command: %w", err) } @@ -62,7 +61,7 @@ func Reply(resp sdk.CommandResponse) error { return fmt.Errorf("failed marshalling CommandResponse to bytes: %w", err) } - ptr, cleanup := internal.Write(bytes) + ptr, cleanup := Write(bytes) defer cleanup() _reply(ptr, uint32(len(bytes))) diff --git a/wasm/imports.go b/internal/wasm/imports.go similarity index 100% rename from wasm/imports.go rename to internal/wasm/imports.go diff --git a/wasm/imports_stub.go b/internal/wasm/imports_stub.go similarity index 100% rename from wasm/imports_stub.go rename to internal/wasm/imports_stub.go diff --git a/internal/memory.go b/internal/wasm/memory.go similarity index 91% rename from internal/memory.go rename to internal/wasm/memory.go index dae2526..6722636 100644 --- a/internal/memory.go +++ b/internal/wasm/memory.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package internal +package wasm import ( "fmt" @@ -21,7 +21,7 @@ import ( var allocations = make(map[uintptr][]byte) -func Allocate(size uint32) (uint32, func()) { +func allocate(size uint32) (uint32, func()) { fmt.Printf("allocating %v bytes\n", size) return Write(make([]byte, size)) @@ -40,7 +40,7 @@ func free(ptr unsafe.Pointer) { } } -func PtrToByteArray(ptr uint32, size uint32) []byte { +func ptrToByteArray(ptr uint32, size uint32) []byte { return unsafe.Slice((*byte)(unsafe.Pointer(uintptr(ptr))), size) } diff --git a/run.go b/run/run.go similarity index 86% rename from run.go rename to run/run.go index 2b367a2..07bef37 100644 --- a/run.go +++ b/run/run.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sdk +package run import ( "context" @@ -20,7 +20,8 @@ import ( "fmt" "os" - "github.com/conduitio/conduit-processor-sdk/wasm" + sdk "github.com/conduitio/conduit-processor-sdk" + "github.com/conduitio/conduit-processor-sdk/internal/wasm" ) // Run is the 'entry point' for a processor. It runs a @@ -28,13 +29,13 @@ import ( // communicates with Conduit. // // A processor plugin needs to call this function in its main() function. -func Run(p Processor) { +func Run(p sdk.Processor) { for { cmd, err := wasm.NextCommand() if err != nil { _, _ = fmt.Fprintf(os.Stderr, "failed retrieving next command: %v", err) exitCode := 1 - if errors.Is(err, ErrNoMoreCommands) { + if errors.Is(err, sdk.ErrNoMoreCommands) { exitCode = 0 } os.Exit(exitCode)