module Baikal
Baikal
is a tool for generating, parsing and modifying binary objects.
Constants
- VERSION
Public Class Methods
hexdump(data_source, port = $stdout, format = Hexdump::DEFAULT_HEXDUMP_FORMAT)
click to toggle source
Hexdumps bytes from data_source
into the given port
(by default, +$stdout+) using the given format (by default, DEFAULT_HEXDUMP_FORMAT
). Uses the length
method of data_source
to determine byte count and the []
method with integer range arguments to extract row-sized slices. data_source
being a String
instance behaves as expected.
# File lib/baikal/hexdump.rb, line 9 def Baikal::hexdump data_source, port = $stdout, format = Hexdump::DEFAULT_HEXDUMP_FORMAT row = Hexdump::Row.new row.expected_size = format.bytes_per_row # iterate over rows row.offset = 0 block_row_counter = 0 while row.offset < data_source.bytesize do if format.rows_per_block != 0 then block_row_counter += 1 if block_row_counter == format.rows_per_block then port.puts # block separator block_row_counter = 0 end end row.data = data_source.unpack "@#{row.offset} C#{format.bytes_per_row}" format.format_row row, port row.offset += format.bytes_per_row end return end