github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/wasm/binary/memory.go (about) 1 package binary 2 3 import ( 4 "bytes" 5 6 "github.com/bananabytelabs/wazero/internal/wasm" 7 ) 8 9 // decodeMemory returns the api.Memory decoded with the WebAssembly 1.0 (20191205) Binary Format. 10 // 11 // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#binary-memory 12 func decodeMemory( 13 r *bytes.Reader, 14 memorySizer func(minPages uint32, maxPages *uint32) (min, capacity, max uint32), 15 memoryLimitPages uint32, 16 ) (*wasm.Memory, error) { 17 min, maxP, err := decodeLimitsType(r) 18 if err != nil { 19 return nil, err 20 } 21 22 min, capacity, max := memorySizer(min, maxP) 23 mem := &wasm.Memory{Min: min, Cap: capacity, Max: max, IsMaxEncoded: maxP != nil} 24 25 return mem, mem.Validate(memoryLimitPages) 26 }