Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rqtrotate/extensions.rb

Overview

ruby’s unpack can’t extract signed big-endian longs (although I’m going to submit a patch to ruby-core to do so). this method compensates for that.

Instance Method Summary collapse

Instance Method Details

#signed_bigendian_unpackObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rqtrotate/extensions.rb', line 19

def signed_bigendian_unpack()
  arr = self.unpack("C*")
  result = []

  # the data is big-endian (netowrk order). if we're on a
  # little endian platform we'll have	to reverse the bytes
  if [1, 0].pack("N*") == [1, 0].pack("L*")
    result = arr
  else
    arr.each_slice(4) do |slice|
      result += slice.reverse
    end
  end

  result.pack('c*').unpack("l*")
end