private function createHeader($cmd, $bytes)
    {
        $retval = chr($cmd);

        $bytes_left = $bytes;
        do {
            $byte = $bytes_left % 128;
            $bytes_left >>= 7;

            if($bytes_left>0) {
              $byte = $byte | 0x80;
            }

            $retval.=chr($byte);

        } while($bytes_left>0);

        return $retval;
    }