Sha256: b737bd544e5d64ef83adedce9d0563cbd5f8f5753f93a41af56705ba31d7e4c1

Contents?: true

Size: 756 Bytes

Versions: 12

Compression:

Stored size: 756 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.chars.to_a.reverse.join
      end

      def self.unpack_64_big_endian(data)
        data = data.chars.to_a.reverse.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

12 entries across 12 versions & 1 rubygems

Version Path
amq-protocol-0.8.0 lib/amq/hacks.rb
amq-protocol-0.7.0 lib/amq/hacks.rb
amq-protocol-0.7.0.beta2 lib/amq/hacks.rb
amq-protocol-0.7.0.beta1 lib/amq/hacks.rb
amq-protocol-0.7.0.alpha7 lib/amq/hacks.rb
amq-protocol-0.7.0.alpha6 lib/amq/hacks.rb
amq-protocol-0.7.0.alpha5 lib/amq/hacks.rb
amq-protocol-0.7.0.alpha4 lib/amq/hacks.rb
amq-protocol-0.7.0.alpha2 lib/amq/hacks.rb
amq-protocol-0.7.0.alpha1 lib/amq/hacks.rb
amq-protocol-0.6.0.pre lib/amq/hacks.rb
amq-protocol-0.5.0 lib/amq/hacks.rb