package binary

import (
	
	

	
	
)

// decodeGlobal returns the api.Global decoded with the WebAssembly 1.0 (20191205) Binary Format.
//
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#binary-global
func decodeGlobal( *bytes.Reader,  api.CoreFeatures,  *wasm.Global) ( error) {
	.Type,  = decodeGlobalType()
	if  != nil {
		return 
	}

	 = decodeConstantExpression(, , &.Init)
	return
}

// decodeGlobalType returns the wasm.GlobalType decoded with the WebAssembly 1.0 (20191205) Binary Format.
//
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#binary-globaltype
func decodeGlobalType( *bytes.Reader) (wasm.GlobalType, error) {
	,  := decodeValueTypes(, 1)
	if  != nil {
		return wasm.GlobalType{}, fmt.Errorf("read value type: %w", )
	}

	 := wasm.GlobalType{
		ValType: [0],
	}

	,  := .ReadByte()
	if  != nil {
		return wasm.GlobalType{}, fmt.Errorf("read mutablity: %w", )
	}

	switch  := ;  {
	case 0x00: // not mutable
	case 0x01: // mutable
		.Mutable = true
	default:
		return wasm.GlobalType{}, fmt.Errorf("%w for mutability: %#x != 0x00 or 0x01", ErrInvalidByte, )
	}
	return , nil
}