PHP code example of clue / qdatastream

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

    

clue / qdatastream example snippets


$user = new stdClass;
$user->id = 10;
$user->active = true;
$user->name = 'Alice';

$writer = new Writer();
$writer->writeUInt($user->id);
$writer->writeBool($user->active);
$writer->writeQString($user->name);

$data = (string)$writer
file_put_contents('user.dat', $data);

$data = file_get_contents('user.dat');
$reader = new Reader($data);

$user = new stdClass();
$user->id = $reader->readUInt();
$user->active = $reader->readBool();
$user->name = $reader->readQString();

$variant = new QVariant(100, Types::TYPE_USHORT);

$writer = new Writer();
$writer->writeQVariant($variant);

$data = (string)$writer;
$reader = new Reader($data);
$value = $reader->readQVariant();

assert($value === 100);

$rows = [
    (object)[
        'id' => 10,
        'name' => 'Alice',
        'active' => true,
        'groups' => ['admin', 'staff']
    ]
];

$writer = new Writer();
$writer->writeQVariant($rows);

$data = (string)$writer;
$reader = new Reader($data);
$values = $reader->readQVariant();

assert(count($values) === 1);
assert($values[0]->id === 10);
assert($values[0]->groups[0] === 'admin');