Skip to content

Commit

Permalink
Revert "move wasm"
Browse files Browse the repository at this point in the history
This reverts commit 5c16e18.
  • Loading branch information
hariso committed Jan 4, 2024
1 parent 5c16e18 commit 4f61ece
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
7 changes: 3 additions & 4 deletions wasm/command_actions.go → internal/wasm/command_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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)))

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/memory.go → internal/wasm/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package internal
package wasm

import (
"fmt"
Expand All @@ -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))
Expand All @@ -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)
}

Expand Down
9 changes: 5 additions & 4 deletions run.go → run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package sdk
package run

import (
"context"
"errors"
"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
// 'get a command, send a reply' loop through which it
// 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)
Expand Down

0 comments on commit 4f61ece

Please sign in to comment.