Class: SCON::Conversions

Inherits:
Object
  • Object
show all
Defined in:
lib/scon.rb

Class Method Summary collapse

Class Method Details

.float_bytes(float) ⇒ Object



41
42
43
# File 'lib/scon.rb', line 41

def self.float_bytes float
  [float].pack("e").bytes
end

.int_bytes(int) ⇒ Object



18
19
20
# File 'lib/scon.rb', line 18

def self.int_bytes int
  [int].pack("i<").bytes
end

.long_bytes(long) ⇒ Object



26
27
28
# File 'lib/scon.rb', line 26

def self.long_bytes long
  [long].pack("q<").bytes
end

.short_bytes(short) ⇒ Object



22
23
24
# File 'lib/scon.rb', line 22

def self.short_bytes short
  [short].pack("s<").bytes
end

.string_bytes(str) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/scon.rb', line 30

def self.string_bytes str
  bytes = str.bytes
  instr = 0xD0
  if bytes.length < 32
    instr += bytes.length
  else
    bytes << 0x03
  end
  [instr, bytes]
end