io.aviso.binary

Utilities for formatting binary data (byte arrays) or binary deltas.

BinaryData

protocol

Allows various data sources to be treated as a byte-array data type that supports a length and random access to individual bytes.

BinaryData is extended onto byte arrays, onto String, and onto nil.

members

byte-at

(byte-at this index)

The byte value at a specific offset.

data-length

(data-length this)

The total number of bytes available.

format-binary

(format-binary data)(format-binary data options)

Formats the data using write-binary and returns the result as a string.

format-binary-delta

(format-binary-delta expected actual)

Formats the delta using write-binary-delta and returns the result as a string.

write-binary

(write-binary data)(write-binary data options)

Formats a BinaryData into a hex-dump string, consisting of multiple lines; each line formatted as:

0000: 43 68 6F 6F 73 65 20 69 6D 6D 75 74 61 62 69 6C 69 74 79 2C 20 61 6E 64 20 73 65 65 20 77 68 65
0020: 72 65 20 74 68 61 74 20 74 61 6B 65 73 20 79 6F 75 2E

The full version specifies:

  • BinaryData to write
  • option keys and values:
    :ascii - boolean
    true to enable ASCII mode
    :line-bytes - number
    number of bytes per line (defaults to 16 for ASCII, 32 otherwise)

In ASCII mode, the output is 16 bytes per line, but each line includes the ASCII printable characters:

0000: 43 68 6F 6F 73 65 20 69 6D 6D 75 74 61 62 69 6C |Choose immutabil|
0010: 69 74 79 2C 20 61 6E 64 20 73 65 65 20 77 68 65 |ity, and see whe|
0020: 72 65 20 74 68 61 74 20 74 61 6B 65 73 20 79 6F |re that takes yo|
0030: 75 2E                                           |u.              |

A placeholder character (a space with magenta background) is used for any non-printable character.

write-binary-delta

(write-binary-delta expected actual)

Formats a hex dump of the expected data (on the left) and actual data (on the right). Bytes that do not match are highlighted in green on the expected side, and red on the actual side. When one side is shorter than the other, it is padded with -- placeholders to make this more clearly visible.

expected and actual are BinaryData.

Display 16 bytes (from each data set) per line.