github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/testing/binaryencoding/data.go (about)

     1  package binaryencoding
     2  
     3  import (
     4  	"github.com/bananabytelabs/wazero/internal/leb128"
     5  	"github.com/bananabytelabs/wazero/internal/wasm"
     6  )
     7  
     8  func encodeDataSegment(d *wasm.DataSegment) (ret []byte) {
     9  	// Currently multiple memories are not supported.
    10  	if d.Passive {
    11  		ret = append(ret, leb128.EncodeInt32(1)...)
    12  	} else {
    13  		ret = append(ret, leb128.EncodeInt32(0)...) // active segment
    14  		ret = append(ret, encodeConstantExpression(d.OffsetExpression)...)
    15  	}
    16  	ret = append(ret, leb128.EncodeUint32(uint32(len(d.Init)))...)
    17  	ret = append(ret, d.Init...)
    18  	return
    19  }