How do references work in igbinary?

159 views
Skip to first unread message

Arjen

unread,
Jul 12, 2011, 9:25:39 AM7/12/11
to igbinary development list
Hi List,

I've built a low-level Java-implementation to allow me to construct
data in either php 'serialize' or igbinary 'serialize'. This worked
pretty well in both cases. And yes, igbinary is quite a bit faster,
both at the java serialization and php unserialization.

Both my igbinary and php-serialize implementation are more or less
similar in the sense that it was quite easy to create a single
interface. I can pretty easily generate very complex arrays and object
structures.

During development of both versions I couldn't really find a
specification of either serializer, so I had to read the code and try
and and produce whatever the unserializer expected with my Java-
implementations. So I may have overlooked trivial aspects.

I noticed a difference in how references work. In php you get either a
"r" or a "R", (the latter for explicit references). For instance, $a =
new A(); $b = array($a, $a); serialize($b); yields "a:2:{i:0;O:1:"A":0:
{}i:1;r:2;}".
The r-reference in normal serialize is incremented for every value in
the serialization. I.e. any zval (?) that is serialized, excluding
object- and array-keys, could later be referenced. A simple long can
be referenced and by simply manipulating the serialized string I can
make that work with unserialization, although I'm not really sure what
kind of PHP I'd need to write to get the same result from serialize ;)

I can make the object reference from my simple example work in
igbinary using a igbinary_type_objref8/16/32 (and
igbinary_type_ref8/16/32 for arrays).

Am I just reading more in PHP's serialize behaviour than there really
is (or should be)? I.e. can in reality - like igbinary - only Objects
and Array's be referenced? If not, what would be the igbinary
equivalent to also reference simple scalars?
Should I use a igbinary_type_ref (which is called a simple reference
in the code)? And how does that work?

Best regards,

Arjen

Teddy

unread,
Jul 13, 2011, 3:21:56 PM7/13/11
to igbinary development list
Hello,



On Jul 12, 4:25 pm, Arjen <a...@tweakers.net> wrote:
...
> During development of both versions I couldn't really find a
> specification of either serializer, so I had to read the code and try
> and and produce whatever the unserializer expected with my Java-

Hello,

Unfortunately true, no specs in this brave new FOSS world. In any
case, I
really hope you can open source your implementation too. :)

...
> I noticed a difference in how references work. In php you get either a
> "r" or a "R", (the latter for explicit references). For instance, $a =
> new A(); $b = array($a, $a); serialize($b); yields "a:2:{i:0;O:1:"A":0:
> {}i:1;r:2;}".

Indeed there is a bug in while serializing basic scalar references,
just
as https://github.com/igbinary/igbinary/issues/6 describes. Clearly a
bug.
Luckily fixable with relative ease, just haven't got around to that
yet.
Reply all
Reply to author
Forward
0 new messages