github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/testing/binaryencoding/data.go (about)

     1  package binaryencoding
     2  
     3  import (
     4  	"github.com/tetratelabs/wazero/internal/leb128"
     5  	"github.com/tetratelabs/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  }