Class: LibSL::LLS32

Inherits:
LLNumber show all
Defined in:
lib/types.rb

Instance Attribute Summary

Attributes inherited from LLNumber

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LLNumber

endianness, #initialize

Constructor Details

This class inherits a constructor from LibSL::LLNumber

Class Method Details

.decode(data) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
# File 'lib/types.rb', line 244

def self.decode(data)
	s32, data = LLNumber.decode(data, 'l1a*', LLS32)
	if self.endianness == :big
		# Convert to little endian
		s32.value = s32.value >> 24 |
			(s32.value & 0xff0000) >> 8 |
			(s32.value & 0xff00) << 8 |
			(s32.value & 0xff) << 24
	end
	return s32, data
end

Instance Method Details

#encodeObject

Raises:

  • (ArgumentError)


256
257
258
259
260
261
262
263
# File 'lib/types.rb', line 256

def encode()
	raise ArgumentError, "Value out of range: #{@value}" if @value < -0x80000000 or @value > 0x7fffffff
	data = super('l')
	if LLNumber::endianness == :big
		data = data.unpack('C4').reverse.pack('C4')
	end
	return data
end