PHP code example of themainframe / php-binary

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

    

themainframe / php-binary example snippets


$builder = new Binary\SchemaBuilder;
$schema = $builder->createFromArray(json_decode('

    {
       "sometext": {
           "_type": "Text",
           "size": 4
       },
       "somebyte": {
           "_type": "UnsignedInteger",
           "size": 1
       },
       "somefields": {
           "_type": "Compound",
           "count": "@somebyte",
           "_fields": {
               "footext": {
                   "_type": "Text",
                   "size": 2
               },
               "foobyte": {
                   "_type": "UnsignedInteger",
                   "size": 1
               }
           }
       }
    }

', true));

$stream = new Binary\Stream\StringStream("FOOO\x03LOLLOMLON");
$result = $schema->readStream($stream);