Skip to content

Commit

Permalink
move wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
hariso committed Jan 4, 2024
1 parent 48bf248 commit 5c16e18
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions internal/wasm/memory.go → internal/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 wasm
package internal

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: 4 additions & 5 deletions run/run.go → run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package run
package sdk

import (
"context"
"errors"
"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
// '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 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)
Expand Down
7 changes: 4 additions & 3 deletions internal/wasm/command_actions.go → wasm/command_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"

sdk "github.com/conduitio/conduit-processor-sdk"

Check failure on line 20 in wasm/command_actions.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/conduitio/conduit-processor-sdk (Config.Importer.Import(github.com/conduitio/conduit-processor-sdk) returned nil but no error) (typecheck)
"github.com/conduitio/conduit-processor-sdk/internal"
"github.com/conduitio/conduit-processor-sdk/proto"

Check failure on line 22 in wasm/command_actions.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/conduitio/conduit-processor-sdk/proto (Config.Importer.Import(github.com/conduitio/conduit-processor-sdk/proto) returned nil but no error) (typecheck)
)

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

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 5c16e18

Please sign in to comment.