Module: Lignite::Bytes

Included in:
Assembler, Message, Message, MessageSender, OpCompiler, RbfObject, SystemCommands
Defined in:
lib/lignite/bytes.rb

Overview

Shortcut methods to convert between data and their byte representation

Instance Method Summary collapse

Instance Method Details

#f32(float) ⇒ Object



16
17
18
# File 'lib/lignite/bytes.rb', line 16

def f32(float)
  [float].pack("e")
end

#hexdump(s) ⇒ Object



36
37
38
# File 'lib/lignite/bytes.rb', line 36

def hexdump(s)
  s.unpack("H*").first
end

#u16(n) ⇒ Object



8
9
10
# File 'lib/lignite/bytes.rb', line 8

def u16(n)
  u8(n & 0xff) + u8(n >> 8)
end

#u32(n) ⇒ Object



12
13
14
# File 'lib/lignite/bytes.rb', line 12

def u32(n)
  u16(n & 0xffff) + u16(n >> 16)
end

#u8(n) ⇒ Object



4
5
6
# File 'lib/lignite/bytes.rb', line 4

def u8(n)
  (n & 0xff).chr
end

#unpack_f32(s) ⇒ Object



32
33
34
# File 'lib/lignite/bytes.rb', line 32

def unpack_f32(s)
  s.unpack("e").first
end

#unpack_u16(s) ⇒ Object



24
25
26
# File 'lib/lignite/bytes.rb', line 24

def unpack_u16(s)
  s.unpack("S<").first
end

#unpack_u32(s) ⇒ Object



28
29
30
# File 'lib/lignite/bytes.rb', line 28

def unpack_u32(s)
  s.unpack("L<").first
end

#unpack_u8(s) ⇒ Object



20
21
22
# File 'lib/lignite/bytes.rb', line 20

def unpack_u8(s)
  s.unpack("C").first
end