Module: Ant::DataUtilities
- Included in:
- Channel::EventCallbacks, ResponseCallbacks
- Defined in:
- lib/ant/mixins.rb,
ext/ant_ext/channel.c
Constant Summary collapse
- VISIBLES =
The range of ASCII codes to show literally in a hexdump
32..126
Class Method Summary collapse
-
.hexdump(data, line_size = 8) ⇒ Object
Return the given data in hexdump format.
Class Method Details
.hexdump(data, line_size = 8) ⇒ Object
Return the given data in hexdump format.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ant/mixins.rb', line 20 def hexdump( data, line_size=8 ) hex_width = line_size * 5 return data.bytes.each_slice( line_size ).with_index.map do |chunk, line| bytes = chunk.map do |b| "0x%02x" % [ b ] end.join( ' ' ) stripped_bytes = chunk.map {|c| VISIBLES.include?(c) ? c.chr : '.'}.join "%04x: %*s | %*s |" % [ line, -hex_width, bytes, -line_size, stripped_bytes ] end.join( "\n" ) end |