static function packHexString(&$buffer, $str) { if (!preg_match("/^(0x)?([a-f0-9]+)\$/", $str, $match)) { throw new \Exception("Invalid hex string format"); } $str = $match[2]; $len = strlen($str); if ($len % 2 != 0) { throw new \Exception("Hex string should have an even number of nibbles"); } for ($x = 0; $x < $len; $x += 2) { Buffer::packInt8u($buffer, "0x" . substr($str, $x, 2)); } return true; }