Module: RestfulX::AMF::Pure::WriteIOHelpers

Included in:
RxAMFSerializer
Defined in:
lib/restfulx/amf/pure/io_helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#byte_orderObject



40
41
42
43
44
45
46
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 40

def byte_order
  if [0x12345678].pack("L") == "\x12\x34\x56\x78"
    :BigEndian
  else
    :LittleEndian
  end
end

#byte_order_little?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 48

def byte_order_little?
  (byte_order == :LittleEndian) ? true : false;
end

#pack_double(double) ⇒ Object



22
23
24
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 22

def pack_double(double)
  [double].pack('G')
end

#pack_int16_network(val) ⇒ Object



30
31
32
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 30

def pack_int16_network(val)
  [val].pack('n')
end

#pack_int8(val) ⇒ Object



26
27
28
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 26

def pack_int8(val)
  [val].pack('c')
end

#pack_integer(integer) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 3

def pack_integer(integer)
  integer = integer & 0x1fffffff
  if(integer < 0x80)
    [integer].pack('c')
  elsif(integer < 0x4000)
    [integer >> 7 & 0x7f | 0x80].pack('c')+
    [integer & 0x7f].pack('c')
  elsif(integer < 0x200000)
    [integer >> 14 & 0x7f | 0x80].pack('c') +
    [integer >> 7 & 0x7f | 0x80].pack('c') +
    [integer & 0x7f].pack('c')
  else
    [integer >> 22 & 0x7f | 0x80].pack('c')+
    [integer >> 15 & 0x7f | 0x80].pack('c')+
    [integer >> 8 & 0x7f | 0x80].pack('c')+
    [integer & 0xff].pack('c')
  end
end

#pack_word32_network(val) ⇒ Object



34
35
36
37
38
# File 'lib/restfulx/amf/pure/io_helpers.rb', line 34

def pack_word32_network(val)
  str = [val].pack('L')
  str.reverse! if byte_order_little? # swap bytes as native=little (and we want network)
  str
end