Sha256: 6d1574ebccdb20408f3a8b84ebb0a765f100975f2ec10f9e9446bf31f9491815

Contents?: true

Size: 778 Bytes

Versions: 20

Compression:

Stored size: 778 Bytes

Contents

# encoding: binary

# Ruby doesn't support pack to/unpack from
# 64bit string in network byte order.
module AMQ
  module Hacks
    BIG_ENDIAN = ([1].pack("s") == "\x00\x01")
    Q = "Q".freeze

    if BIG_ENDIAN
      def self.pack_64_big_endian(long_long)
        [long_long].pack(Q)
      end

      def self.unpack_64_big_endian(data)
        data.unpack(Q)
      end
    else
      def self.pack_64_big_endian(long_long)
        result = [long_long].pack(Q)
        result.bytes.to_a.reverse.map(&:chr).join
      end

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

# AMQ::Hacks.pack_64_big_endian(17)
# AMQ::Hacks.unpack_64_big_endian("\x00\x00\x00\x00\x00\x00\x00\x11")

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
amq-protocol-1.2.0 lib/amq/hacks.rb
amq-protocol-1.1.0 lib/amq/hacks.rb
amq-protocol-1.0.1 lib/amq/hacks.rb
amq-protocol-1.0.0 lib/amq/hacks.rb
amq-protocol-0.9.5 lib/amq/hacks.rb
amq-protocol-1.0.0.pre7 lib/amq/hacks.rb
amq-protocol-0.9.4 lib/amq/hacks.rb
amq-protocol-1.0.0.pre6 lib/amq/hacks.rb
amq-protocol-0.9.3 lib/amq/hacks.rb
amq-protocol-1.0.0.pre5 lib/amq/hacks.rb
amq-protocol-0.9.2 lib/amq/hacks.rb
amq-protocol-1.0.0.pre4 lib/amq/hacks.rb
amq-protocol-1.0.0.pre3 lib/amq/hacks.rb
amq-protocol-1.0.0.pre2 lib/amq/hacks.rb
amq-protocol-0.9.1 lib/amq/hacks.rb
amq-protocol-1.0.0.pre1 lib/amq/hacks.rb
amq-protocol-0.9.0 lib/amq/hacks.rb
amq-protocol-0.8.4 lib/amq/hacks.rb
amq-protocol-0.8.3 lib/amq/hacks.rb
amq-protocol-0.8.1 lib/amq/hacks.rb