Skip to content

Commit

Permalink
wasi: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
colindickson committed Jan 11, 2024
1 parent 84fc7f6 commit 2d822dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
36 changes: 0 additions & 36 deletions wasm/wasi/args.go

This file was deleted.

29 changes: 29 additions & 0 deletions wasm/wasi/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"os"
"sync"

"github.com/protocolbuffers/protoscope"

"github.com/dustin/go-humanize"
"github.com/streamingfast/substreams/wasm"
"github.com/streamingfast/substreams/wasm/wasi/fs"
Expand Down Expand Up @@ -163,3 +165,30 @@ func (w *LogWriter) Write(p []byte) (n int, err error) {
call.AppendLog(logMessage)
return len(p), nil
}

func marshallArgs(args []wasm.Argument) ([]byte, error) {
scopeData := ""
fieldCount := 0
writeStoreCount := 0
readerStoreCount := 0
for _, arg := range args {
fieldCount++
switch v := arg.(type) {
case *wasm.StoreWriterOutput:
scopeData += fmt.Sprintf("%d: %d\n", fieldCount, writeStoreCount)
writeStoreCount++
case *wasm.StoreReaderInput:
scopeData += fmt.Sprintf("%d: %d\n", fieldCount, readerStoreCount)
readerStoreCount++
case wasm.ProtoScopeValueArgument:
scopeData += fmt.Sprintf("%d: %s\n", fieldCount, v.ProtoScopeValue())
default:
panic(fmt.Sprintf("unknown wasm argument type %T", v))
}
}
data, err := protoscope.NewScanner(scopeData).Exec()
if err != nil {
return nil, fmt.Errorf("scanning args: %w (scopeData: %s)", err, scopeData)
}
return data, nil
}

0 comments on commit 2d822dd

Please sign in to comment.