Class: LibSL::LLS16
Instance Attribute Summary
Attributes inherited from LLNumber
#value
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from LLNumber
endianness, #initialize
Class Method Details
.decode(data) ⇒ Object
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/types.rb', line 222
def self.decode(data)
s16, data = LLNumber.decode(data, 's1a*', LLS16)
if self.endianness == :big
ms = s16.value >> 8
ls = s16 - (ms << 8)
s16.value = (ls << 8) + ms
end
return s16, data
end
|
Instance Method Details
#encode ⇒ Object
233
234
235
236
237
238
239
240
|
# File 'lib/types.rb', line 233
def encode()
raise ArgumentError, "Value out of range: #{@value}" if @value < -0x8000 or @value > 0x7fff
data = super('s')
if LLNumber::endianness == :big
data = data.unpack('C2').reverse.pack('C2')
end
return data
end
|