Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-libav.rb

Instance Method Summary collapse

Instance Method Details

#hexdumpObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ffi-libav.rb', line 21

def hexdump
  buf = ""
  offset = 0
  words = self.unpack("N%d" % (self.length/4.0).ceil)
  until words.empty?
    line = words.shift(4).compact
    buf += sprintf("[%04x] " + ("%08x " * line.size) + "|%s|\n", 
                   offset * 16, *line, 
                   line.pack("N%d" % line.size).tr("^\040-\176","."))
    offset += 1
  end
  buf
end