package binary

import (
	
	

	
)

// decodeLimitsType returns the `limitsType` (min, max) decoded with the WebAssembly 1.0 (20191205) Binary Format.
//
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#limits%E2%91%A6
//
// Extended in threads proposal: https://webassembly.github.io/threads/core/binary/types.html#limits
func decodeLimitsType( *bytes.Reader) ( uint32,  *uint32,  bool,  error) {
	var  byte
	if ,  = .ReadByte();  != nil {
		 = fmt.Errorf("read leading byte: %v", )
		return
	}

	switch  {
	case 0x00, 0x02:
		, _,  = leb128.DecodeUint32()
		if  != nil {
			 = fmt.Errorf("read min of limit: %v", )
		}
	case 0x01, 0x03:
		, _,  = leb128.DecodeUint32()
		if  != nil {
			 = fmt.Errorf("read min of limit: %v", )
			return
		}
		var  uint32
		if , _,  = leb128.DecodeUint32();  != nil {
			 = fmt.Errorf("read max of limit: %v", )
		} else {
			 = &
		}
	default:
		 = fmt.Errorf("%v for limits: %#x not in (0x00, 0x01, 0x02, 0x03)", ErrInvalidByte, )
	}

	 =  == 0x02 ||  == 0x03

	return
}