PHPackages                             themainframe/php-binary - 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. themainframe/php-binary

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

themainframe/php-binary
=======================

A PHP library for parsing structured binary streams.

v0.2.0(10y ago)321.6k5[1 issues](https://github.com/themainframe/php-binary/issues)MITPHPPHP &gt;=5.3.0

Since Mar 27Pushed 10y ago3 watchersCompare

[ Source](https://github.com/themainframe/php-binary)[ Packagist](https://packagist.org/packages/themainframe/php-binary)[ RSS](/packages/themainframe-php-binary/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)DependenciesVersions (8)Used By (0)

php-binary [![Build Status](https://camo.githubusercontent.com/8c3bad2ffd8e970d1632f637bf45aacaf9baf63ab6131d1022159f0584b9f1b1/68747470733a2f2f7472617669732d63692e6f72672f7468656d61696e6672616d652f7068702d62696e6172792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/themainframe/php-binary)
===============================================================================================================================================================================================================================================================================================================

[](#php-binary-)

A PHP library for parsing structured binary streams.

Documentation
-------------

[](#documentation)

Documentation can be found in the `documentation` directory, as well as online at [php-binary.damow.net](http://php-binary.damow.net)

Usage
-----

[](#usage)

Here is an example binary format:

1. **4 bytes** of text.
2. **1 byte** unsigned integer.
3. A field of **2 bytes** of text followed by a **1 byte** unsigned integer; repeated *n* times, where *n* is a backreference to the byte described in point **2**.

### Writing a Parser Schema

[](#writing-a-parser-schema)

This format can be parsed as follows. In this example, the schema is described using JSON for clarity, though in practise any array may be used.

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

### Parsing a Stream

[](#parsing-a-stream)

You can have php-binary parse a generic stream of bytes and output fields as an associative array matching your schema definition.

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

The resulting associative array in `$result` (shown here as JSON for clarity) would contain:

```
{
    "sometext": "FOOO",
    "somebyte": 3,
    "somefields": [
        {
            "footext": "LO",
            "foobyte": 76
        },
        {
            "footext": "LO",
            "foobyte": 77
        },
        {
            "footext": "LO",
            "foobyte": 78
        }
    ]
}
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.5% 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 ~532 days

Total

2

Last Release

3687d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/54750?v=4)[Damo](/maintainers/themainframe)[@themainframe](https://github.com/themainframe)

---

Top Contributors

[![themainframe](https://avatars.githubusercontent.com/u/54750?v=4)](https://github.com/themainframe "themainframe (107 commits)")[![klermonte](https://avatars.githubusercontent.com/u/2529340?v=4)](https://github.com/klermonte "klermonte (2 commits)")[![ShaneEgan](https://avatars.githubusercontent.com/u/3873113?v=4)](https://github.com/ShaneEgan "ShaneEgan (2 commits)")[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (1 commits)")

---

Tags

bytesparsingphpschema

### Embed Badge

![Health badge](/badges/themainframe-php-binary/health.svg)

```
[![Health](https://phpackages.com/badges/themainframe-php-binary/health.svg)](https://phpackages.com/packages/themainframe-php-binary)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[karriere/json-decoder

JsonDecoder implementation that allows you to convert your JSON data into PHP class objects

140439.4k12](/packages/karriere-json-decoder)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)

PHPackages © 2026

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