Module: RocketAMF::Pure::WriteIOHelpers
- Included in:
- Envelope, Serializer
- Defined in:
- lib/rocketamf/pure/io_helpers.rb
Overview
:nodoc:
Instance Method Summary collapse
- #byte_order ⇒ Object
- #byte_order_little? ⇒ Boolean
- #pack_double(double) ⇒ Object
- #pack_int16_network(val) ⇒ Object
- #pack_int8(val) ⇒ Object
- #pack_integer(integer) ⇒ Object
- #pack_word32_network(val) ⇒ Object
Instance Method Details
#byte_order ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 81 def byte_order if [0x12345678].pack("L") == "\x12\x34\x56\x78" :BigEndian else :LittleEndian end end |
#byte_order_little? ⇒ Boolean
89 90 91 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 89 def byte_order_little? (byte_order == :LittleEndian) ? true : false; end |
#pack_double(double) ⇒ Object
63 64 65 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 63 def pack_double(double) [double].pack('G') end |
#pack_int16_network(val) ⇒ Object
71 72 73 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 71 def pack_int16_network(val) [val].pack('n') end |
#pack_int8(val) ⇒ Object
67 68 69 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 67 def pack_int8(val) [val].pack('c') end |
#pack_integer(integer) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 44 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
75 76 77 78 79 |
# File 'lib/rocketamf/pure/io_helpers.rb', line 75 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 |