improved debugging function (dumps raw bytes better)

This commit is contained in:
Thomas Lackner 2013-01-06 23:28:23 -06:00
parent 7caa92b6d7
commit c5f2f62777

View file

@ -94,9 +94,20 @@
$this->options = $options; $this->options = $options;
} }
private function debug($text) { private function debug($text, $binary = false) {
if ($this->options['debug']) if ($this->options['debug']) {
echo "SNAPHAX DEBUG: $text\n"; echo "SNAPHAX DEBUG: $text";
if ($binary !== false) {
// shortened hex repr of binary
$len = strlen($binary);
$tmp = " hex ($len bytes): ";
$tmp.= join(' ', array_map('dechex', array_map('ord', str_split(substr($binary, 0, 16)))));
$tmp.= ' ... ';
$tmp.= join(' ', array_map('dechex', array_map('ord', str_split(substr($binary, -16)))));
echo $tmp;
}
echo "\n";
}
} }
private function isValidBlobHeader($header) { private function isValidBlobHeader($header) {