Sha256: 8eb1d1432e2f4b508befd5dd2760ab86b8d6d4d63776016f1c0e34f75f6aa02c

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'rocketamf/pure/helpers/io_helper_base'

module RocketAMF
  module Pure
    module IOHelperRead #:nodoc:

      include IOHelperBase

      #
      # Methods
      #

      public
      def read_int8(source)
        raise AMFErrorIncomplete.new if source.eof?

        source.read(1).unpack('c').first
      end

      public
      def read_word8(source)
        raise AMFErrorIncomplete.new if source.eof?

        source.read(1).unpack('C').first
      end

      public
      def read_double(source)
        bytes_to_read = 8

        raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

        source.read(bytes_to_read).unpack('G').first
      end

      public
      def read_word16_network(source)
        bytes_to_read = 2

        raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

        source.read(2).unpack('n').first
      end

      public
      def read_int16_network(source)
        bytes_to_read = 2

        raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

        result = source.read(bytes_to_read)
        result.reverse! if byte_order_little? # swap bytes as native=little (and we want network)
        result.unpack('s').first
      end

      public
      def read_word32_network(source)
        bytes_to_read = 4

        raise AMFErrorIncomplete.new if bytes_to_read > (source.size - source.pos)

        source.read(bytes_to_read).unpack('N').first
      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_read.rb
mrpin-rocketamf-2.0.0 lib/rocketamf/pure/helpers/io_helper_read.rb