I think the most clear way is to apply the new $offset argument and then the 
old way to skip first bytes of input string.
So unpack("@$skip/N4", $message, $offset) will skip $offset+$skip.
Actually, this is the way  how the proposed patch works.

Thanks. Dmitry.


________________________________________
From: Leigh <lei...@gmail.com>
Sent: Thursday, February 25, 2016 18:20
To: Dmitry Stogov
Cc: Nikita Popov; internals@lists.php.net; Hynek Bartoš
Subject: Re: [PHP-DEV] Fw: unpack()

On 25 February 2016 at 13:02, Dmitry Stogov <dmi...@zend.com> wrote:
>
> I've just got to know about possible usage of "@" in unpack(), but it seems
> doesn't work at all
>
> $ sapi/cli/php -r 'var_dump(unpack("@0l", "\x01\x00\x00\x00")); '
> array(0) {
> }
>
> Do I use it properly?
>
> Thanks. Dmitry.
>

As Nikita said, you need the "/". I use this operator when processing
streams of binary data.

Trimmed down example:

while ($blocks--) {
    list(, $x0, $x1, $x2, $x3) = unpack("@$offset/N4", $message);
    //...
    $offset += 16;
}

The dynamic format string is kind of nasty though, so no objections to
an additional parameter making things clearer, however, what is to be
done if an offset is specified in both the format string and the
additional parameter? Does one override the other? Are they additive?

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to