Sha256: a03ac693a1572f409d19d7d322f18c779d942059a6a878bdf242d6a0360e5be4

Contents?: true

Size: 1.23 KB

Versions: 28

Compression:

Stored size: 1.23 KB

Contents

# encoding: binary

require 'gorgon_amq/endianness'

module GorgonAMQ
  # Implements pack to/unpack from 64bit string in network byte order
  # compatible with Ruby 1.8+.
  module Pack
    UINT64 = "Q".freeze
    INT16  = "c".freeze

    if Endianness.big_endian?
      def self.pack_uint64_big_endian(long_long)
        [long_long].pack(UINT64)
      end

      def self.unpack_uint64_big_endian(data)
        data.unpack(UINT64)
      end

      def self.pack_int16_big_endian(short)
        [long_long].pack(INT16)
      end

      def self.unpack_int16_big_endian(data)
        data.unpack(INT16)
      end
    else
      def self.pack_uint64_big_endian(long_long)
        result = [long_long].pack(UINT64)
        result.bytes.to_a.reverse.map(&:chr).join
      end

      def self.unpack_uint64_big_endian(data)
        data = data.bytes.to_a.reverse.map(&:chr).join
        data.unpack(UINT64)
      end

      def self.pack_int16_big_endian(short)
        result = [long_long].pack(INT16)
        result.bytes.to_a.reverse.map(&:chr).join
      end

      def self.unpack_int16_big_endian(data)
        data = data.bytes.to_a.reverse.map(&:chr).join
        data.unpack(INT16)
      end
    end
  end

  # Backwards compatibility
  Hacks = Pack
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
gorgon-0.11.1 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.11.0 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.10.5 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.10.4 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.10.3 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.10.2 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.10.1 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.10.0 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.9.0 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.8.4 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.8.3 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.8.2 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.8.1 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.8.0 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.7.1 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.7.0 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.7.0.rc4 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.7.0.rc3 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.7.0.rc2 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb
gorgon-0.7.0.rc1 lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb