PHP code example of typiqally / binary

1. Go to this page and download the library: Download typiqally/binary library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

typiqally / binary example snippets


use Typiqally\Binary\BinaryModel;

class Packet extends BinaryModel
{
    public array $fields = [
        //Name => [Type, Expected length],
        'magic' => ['raw', 4],
        'protocol' => ['numeric', 1],
        'length' => ['numeric', 2],
    ];
}

$model = new Packet("\x12\x34\x56\x78", 10, 1337);

$value = BinarySerializer::serialize($model);
//Output (converted to hex using bin2hex): 123456780a0539

$model = BinarySerializer::deserialize(Packet::class, $value);
//Output (by using the internal __toString function): magic=%124Vx, protocol=10, length=1337