diff --git a/internal/wasm/memory.go b/internal/memory.go similarity index 91% rename from internal/wasm/memory.go rename to internal/memory.go index 6722636..dae2526 100644 --- a/internal/wasm/memory.go +++ b/internal/memory.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package wasm +package internal 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/run.go b/run.go similarity index 86% rename from run/run.go rename to run.go index 07bef37..2b367a2 100644 --- a/run/run.go +++ b/run.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package run +package sdk import ( "context" @@ -20,8 +20,7 @@ import ( "fmt" "os" - sdk "github.com/conduitio/conduit-processor-sdk" - "github.com/conduitio/conduit-processor-sdk/internal/wasm" + "github.com/conduitio/conduit-processor-sdk/wasm" ) // Run is the 'entry point' for a processor. It runs a @@ -29,13 +28,13 @@ import ( // communicates with Conduit. // // A processor plugin needs to call this function in its main() function. -func Run(p sdk.Processor) { +func Run(p 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, sdk.ErrNoMoreCommands) { + if errors.Is(err, ErrNoMoreCommands) { exitCode = 0 } os.Exit(exitCode) diff --git a/internal/wasm/command_actions.go b/wasm/command_actions.go similarity index 90% rename from internal/wasm/command_actions.go rename to wasm/command_actions.go index d14d9de..5e50602 100644 --- a/internal/wasm/command_actions.go +++ b/wasm/command_actions.go @@ -18,6 +18,7 @@ import ( "fmt" sdk "github.com/conduitio/conduit-processor-sdk" + "github.com/conduitio/conduit-processor-sdk/internal" "github.com/conduitio/conduit-processor-sdk/proto" ) @@ -29,7 +30,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 := allocate(defaultCommandSize) + ptr, cleanup := internal.Allocate(defaultCommandSize) defer cleanup() // request Conduit to write the command to the given allocation @@ -47,7 +48,7 @@ func NextCommand() (sdk.Command, error) { } // parse the command - cmd, err := proto.UnmarshalCommand(ptrToByteArray(ptr, resp)) + cmd, err := proto.UnmarshalCommand(internal.PtrToByteArray(ptr, resp)) if err != nil { return nil, fmt.Errorf("failed unmarshalling command: %w", err) } @@ -61,7 +62,7 @@ func Reply(resp sdk.CommandResponse) error { return fmt.Errorf("failed marshalling CommandResponse to bytes: %w", err) } - ptr, cleanup := Write(bytes) + ptr, cleanup := internal.Write(bytes) defer cleanup() _reply(ptr, uint32(len(bytes))) diff --git a/internal/wasm/imports.go b/wasm/imports.go similarity index 100% rename from internal/wasm/imports.go rename to wasm/imports.go diff --git a/internal/wasm/imports_stub.go b/wasm/imports_stub.go similarity index 100% rename from internal/wasm/imports_stub.go rename to wasm/imports_stub.go