Sha256: 330a7c71a4a00da66942f9e2d85144fe86d61fcb065c3d2899f094cf906c20d8

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

require 'rocketamf/pure/helpers/io_helper_base'

module RocketAMF
  module Pure
    module IOHelperWrite #:nodoc:

      include IOHelperBase

      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

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

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

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

      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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mrpin-rocketamf-2.0.1 lib/rocketamf/pure/helpers/io_helper_write.rb
mrpin-rocketamf-2.0.0 lib/rocketamf/pure/helpers/io_helper_write.rb