396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
# File 'lib/scale/base.rb', line 396
def decode(scale_bytes)
puts " BEGIN " + self::TYPE_NAME + ": #{scale_bytes}" if Scale::Types.debug == true
byte_length = self::BYTE_LENGTH
raise "#{self.name} byte length is wrong: #{byte_length}" unless %w[2 3 4 8 16 20 32 64 128 256].include?(byte_length.to_s)
bytes = scale_bytes.get_next_bytes(byte_length)
str = bytes.pack("C*").force_encoding("utf-8")
if str.valid_encoding?
puts " END " + self::TYPE_NAME + ": #{scale_bytes}" if Scale::Types.debug == true
new str
else
puts " END " + self::TYPE_NAME + ": #{scale_bytes}" if Scale::Types.debug == true
new bytes.bytes_to_hex
end
end
|