PHPackages                             clue/qdatastream - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. clue/qdatastream

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

clue/qdatastream
================

Lightweight PHP library that allows exchanging binary data with Qt programs (QDataStream)

v0.8.0(7y ago)516.3k↑200%3[2 issues](https://github.com/clue/qdatastream/issues)1MITPHPPHP &gt;=5.3

Since Apr 28Pushed 4y ago3 watchersCompare

[ Source](https://github.com/clue/qdatastream)[ Packagist](https://packagist.org/packages/clue/qdatastream)[ Docs](https://github.com/clue/php-qdatastream)[ RSS](/packages/clue-qdatastream/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (1)

clue/qdatastream
================

[](#clueqdatastream)

[![CI status](https://github.com/clue/php-qdatastream/workflows/CI/badge.svg)](https://github.com/clue/php-qdatastream/actions)[![installs on Packagist](https://camo.githubusercontent.com/745262bd8adacc5e7e3d0e539d9f0215b887b363e9c7a4323ed4ef12cbb9003b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c75652f716461746173747265616d3f636f6c6f723d626c7565266c6162656c3d696e7374616c6c732532306f6e2532305061636b6167697374)](https://packagist.org/packages/clue/qdatastream)

Lightweight PHP library that allows exchanging binary data with Qt programs (QDataStream)

**Table of contents**

- [Usage](#usage)
    - [Writer](#writer)
    - [Reader](#reader)
    - [QVariant](#qvariant)
    - [Types](#types)
- [Install](#install)
- [Tests](#tests)
- [License](#license)

Usage
-----

[](#usage)

### Writer

[](#writer)

The `Writer` class can be used to build a binary buffer string from the structured data you write to it.

```
$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);
```

See the [class outline](src/Writer.php) for more details.

### Reader

[](#reader)

The `Reader` class can be used to read data from a binary buffer string.

```
$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();
```

See the [class outline](src/Reader.php) for more details.

### QVariant

[](#qvariant)

The `QVariant` class can be used to encapsulate any kind of data with an explicit data type. When writing a `QVariant` to a buffer, it will also include its data type so that reading it back in can be done automatically without having to know the data type in advance.

```
$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);
```

Additionally, you can use the `writeQVariant()` method without having to specify the data type in advance and let this class "guess" an appropriate data type for serialization and add this type information to the serialized data. This works similar to JSON encoding and accepts primitive values of type `int`, `bool`, `string`, `null` and nested structures or type `array` or instances of `stdClass`:

```
$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');
```

Note that associative arrays and `stdClass` objects be will serialized as a "map", while vector arrays will be serialized as a "list". In order to avoid confusion between these similar data structures, using instances of `stdClass` is considered the preferred method in this project.

See the [class outline](src/QVariant.php) for more details.

### Types

[](#types)

The `Types` class exists to work with different data types and offers a number of public constants to work with explicit data types and is otherwise mostly used internally only.

See the [class outline](src/Types.php) for more details.

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This will install the latest supported version:

```
$ composer require clue/qdatastream:^0.8
```

See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+. It's *highly recommended to use PHP 7+* for this project.

The `QString` and `QChar` types use the `ext-mbstring` for converting between different character encodings. If this extension is missing, then this library will use a slighty slower Regex work-around that should otherwise work equally well. Installing `ext-mbstring` is highly recommended.

Tests
-----

[](#tests)

To run the test suite, you first need to clone this repo and then install all dependencies [through Composer](https://getcomposer.org):

```
$ composer install
```

To run the test suite, go to the project root and run:

```
$ php vendor/bin/phpunit
```

License
-------

[](#license)

This project is released under the permissive [MIT license](LICENSE).

> Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~127 days

Total

12

Last Release

2633d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/776829?v=4)[Christian Lück](/maintainers/clue)[@clue](https://github.com/clue)

---

Top Contributors

[![clue](https://avatars.githubusercontent.com/u/776829?v=4)](https://github.com/clue "clue (97 commits)")[![SimonFrings](https://avatars.githubusercontent.com/u/44357440?v=4)](https://github.com/SimonFrings "SimonFrings (6 commits)")[![PaulRotmann](https://avatars.githubusercontent.com/u/85174210?v=4)](https://github.com/PaulRotmann "PaulRotmann (1 commits)")

---

Tags

serializeparsebinaryqtQDataStream

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clue-qdatastream/health.svg)

```
[![Health](https://phpackages.com/badges/clue-qdatastream/health.svg)](https://phpackages.com/packages/clue-qdatastream)
```

###  Alternatives

[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[aranyasen/hl7

HL7 parser, generator and sender.

1951.3M](/packages/aranyasen-hl7)[zumba/json-serializer

Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.

129743.7k13](/packages/zumba-json-serializer)[nihongodera/limelight

A php Japanese language text analyzer and parser.

10678.9k](/packages/nihongodera-limelight)[adci/full-name-parser

Parses a human name

29714.4k5](/packages/adci-full-name-parser)[dimabdc/php-fast-simple-html-dom-parser

PHP Fast Simple HTML DOM parser.

9352.6k](/packages/dimabdc-php-fast-simple-html-dom-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
