Rust

igbinary

Module

igbinary_serialize and igbinary_unserialize, byte-identical to the igbinary extension (3.2, format version 2, igbinary.compact_strings=On) of the PHP image. Appwrite's cache and queue payloads use it.

Every function here is checked against the extension by bin/compat fuzz php-std (operations igbinary.*).

PHPRust
igbinary_serialize($v)serialize
igbinary_unserialize($s)unserialize (strings share the input buffer)
its warnings (igbinary_unserialize_*: ...)Error::Invalid

The format: a 4-byte version header (00 00 00 02), then one value. Integers take the smallest of 1, 2, 4 or 8 bytes with the sign in the type; floats are IEEE 754 big-endian; every non-empty string (values, keys, class names) is written once and referenced by its index after that; arrays and objects are a count and key/value pairs; containers get a reference id in pre-order for back-references.

Identity: PHP writes a back-reference when the same array or object instance appears twice, which a Value (no identity) cannot know. The engine shares one immutable empty array ([] literals, json_decode, unserialize, igbinary_unserialize), so serialize writes every empty array after the first as a back-reference to it, as PHP does for such data. Back-references PHP wrote for other shared instances or PHP references read as copies, and are written in full again. Objects of other classes (__PHP_Incomplete_Class in PHP), recursive structures and nesting deeper than MAX_DEPTH are Error::Unsupported.

Contents

use php_std::igbinary::Error;
Rust
pub enum Error

Why igbinary_unserialize() failed.

Also implements Display.
use php_std::igbinary::serialize;
Rust
pub fn serialize<X: Extension>(value: &Value<X>) -> Vec<u8>

igbinary_serialize($value).

use php_std::igbinary::unserialize;
Rust
pub fn unserialize(input: &Bytes) -> Result<Value, Error>

igbinary_unserialize($data). Strings longer than an inline string share input's buffer.

Rust
pub const MAX_DEPTH: usize = 4096

Nesting deeper than this is refused when reading (PHP recurses without a limit and exhausts its stack eventually).