PHP code example of sysbot / bin

1. Go to this page and download the library: Download sysbot/bin 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/ */

    

sysbot / bin example snippets




ysbot\Bin\Serializer;
use Sysbot\Bin\Deserializer;

// Serialization

$serializer = new Serializer();

$serializer->addLong(15); // adds a 32-bit integer (little-endian)

$long = PHP_INT_MAX;

if (PHP_INT_SIZE === 4) { // 32-bit systems
    // since 32-bit systems can't handle 64-bit numbers, we must relay on the BigInteger class
    $long = BigInteger::of('9223372036854775807');
}
$serializer->addLongLong($long, true); // adds a 64-bit integer (big-endian)

$serializer->addString('Hi mom!'); // adds a string

// casting a Serializer instance to a string will return the bytes
echo bin2hex((string)$serializer); // outputs "0f0000007fffffffffffffff074869206d6f6d21"


// Deserialization

$deserializer = new Deserializer((string)$serializer);

echo $deserializer->readLong(); // reads a 32-bit integer (little-endian), outputs "15"

$long = $deserializer->readLongLong(true); // reads a 64-bit integer (big-endian)

if (PHP_INT_SIZE === 4) {
    $long = (string)$long; // on 32-bit systems, an instance of the BigInteger class will be returned: to get the number, we must cast to string
}

echo $long; // outputs "9223372036854775807"

echo $deserializer->readString(); // reads a string, outputs "Hi mom!"