Module: AMF::Pure::IOHelperWrite

Includes:
IOHelperBase
Included in:
Serializer
Defined in:
lib/amf/pure/helpers/io_helper_write.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from IOHelperBase

#byte_order, #byte_order_little?

Instance Method Details

#pack_double(double) ⇒ Object



29
30
31
# File 'lib/amf/pure/helpers/io_helper_write.rb', line 29

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

#pack_int16_network(val) ⇒ Object



37
38
39
# File 'lib/amf/pure/helpers/io_helper_write.rb', line 37

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

#pack_int8(val) ⇒ Object



33
34
35
# File 'lib/amf/pure/helpers/io_helper_write.rb', line 33

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

#pack_integer(integer) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/amf/pure/helpers/io_helper_write.rb', line 9

def pack_integer(integer)
  integer = integer & 0x1fffffff

  if integer < AMF::AMFConstants::MIN_INT_2_BYTE
    [integer].pack('c')
  elsif integer < AMF::AMFConstants::MIN_INT_3_BYTE
    [integer >> 7 & 0x7f | 0x80].pack('c') +
        [integer & 0x7f].pack('c')
  elsif integer < AMF::AMFConstants::MIN_INT_4_BYTE
    [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



41
42
43
44
45
# File 'lib/amf/pure/helpers/io_helper_write.rb', line 41

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