github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/testing/binaryencoding/limits.go (about) 1 package binaryencoding 2 3 import ( 4 "github.com/tetratelabs/wazero/internal/leb128" 5 ) 6 7 // EncodeLimitsType returns the `limitsType` (min, max) encoded in WebAssembly 1.0 (20191205) Binary Format. 8 // 9 // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#limits%E2%91%A6 10 // 11 // Extended in threads proposal: https://webassembly.github.io/threads/core/binary/types.html#limits 12 func EncodeLimitsType(min uint32, max *uint32, shared bool) []byte { 13 var flag uint32 14 if max != nil { 15 flag = 0x01 16 } 17 if shared { 18 flag |= 0x02 19 } 20 ret := append(leb128.EncodeUint32(flag), leb128.EncodeUint32(min)...) 21 if max != nil { 22 ret = append(ret, leb128.EncodeUint32(*max)...) 23 } 24 return ret 25 }