package binary
import (
"bytes"
"fmt"
"io"
"unicode/utf8"
"unsafe"
"github.com/tetratelabs/wazero/internal/leb128"
"github.com/tetratelabs/wazero/internal/wasm"
)
func decodeValueTypes(r *bytes .Reader , num uint32 ) ([]wasm .ValueType , error ) {
if num == 0 {
return nil , nil
}
ret := make ([]wasm .ValueType , num )
_ , err := io .ReadFull (r , ret )
if err != nil {
return nil , err
}
for _ , v := range ret {
switch v {
case wasm .ValueTypeI32 , wasm .ValueTypeF32 , wasm .ValueTypeI64 , wasm .ValueTypeF64 ,
wasm .ValueTypeExternref , wasm .ValueTypeFuncref , wasm .ValueTypeV128 :
default :
return nil , fmt .Errorf ("invalid value type: %d" , v )
}
}
return ret , nil
}
func decodeUTF8(r *bytes .Reader , contextFormat string , contextArgs ...interface {}) (string , uint32 , error ) {
size , sizeOfSize , err := leb128 .DecodeUint32 (r )
if err != nil {
return "" , 0 , fmt .Errorf ("failed to read %s size: %w" , fmt .Sprintf (contextFormat , contextArgs ...), err )
}
if size == 0 {
return "" , uint32 (sizeOfSize ), nil
}
buf := make ([]byte , size )
if _, err = io .ReadFull (r , buf ); err != nil {
return "" , 0 , fmt .Errorf ("failed to read %s: %w" , fmt .Sprintf (contextFormat , contextArgs ...), err )
}
if !utf8 .Valid (buf ) {
return "" , 0 , fmt .Errorf ("%s is not valid UTF-8" , fmt .Sprintf (contextFormat , contextArgs ...))
}
ret := unsafe .String (&buf [0 ], int (size ))
return ret , size + uint32 (sizeOfSize ), nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .