module HexFormat
Constants
- GROUP_FORMAT_LENGTH
- GROUP_SIZE
- LINE_SIZE
Public Class Methods
format_group(data)
click to toggle source
# File lib/innodb/util/hex_format.rb, line 8 def self.format_group(data) data.map { |n| "%02x" % n.ord }.join(" ") end
format_groups(data, size)
click to toggle source
# File lib/innodb/util/hex_format.rb, line 12 def self.format_groups(data, size) data.each_slice(size).map { |g| format_group(g) }.join(" ") end
format_hex(data) { |format("%08i %-#{GROUP_FORMAT_LENGTH}s |%-#{LINE_SIZE}s|", (i * LINE_SIZE), format_groups(bytes, GROUP_SIZE), format_printable(bytes))| ... }
click to toggle source
# File lib/innodb/util/hex_format.rb, line 20 def self.format_hex(data) data.chars.each_slice(LINE_SIZE).with_index do |bytes, i| yield format("%08i %-#{GROUP_FORMAT_LENGTH}s |%-#{LINE_SIZE}s|", (i * LINE_SIZE), format_groups(bytes, GROUP_SIZE), format_printable(bytes)) end nil end
format_printable(data)
click to toggle source
# File lib/innodb/util/hex_format.rb, line 16 def self.format_printable(data) data.join.gsub(/[^[:print:]]/, ".") end
puts(data, io: $stdout)
click to toggle source
# File lib/innodb/util/hex_format.rb, line 29 def self.puts(data, io: $stdout) format_hex(data) { |line| io.puts(line) } end