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

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

pigeonboys/php-binary-parser
============================

A PHP library for parsing binary data, with full support for signed/unsigned integers and endian-aware formats.

0.9.0(8mo ago)02MITPHPPHP &gt;=8.0

Since Sep 2Pushed 8mo agoCompare

[ Source](https://github.com/pigeonboys/php-binary-parser)[ Packagist](https://packagist.org/packages/pigeonboys/php-binary-parser)[ RSS](/packages/pigeonboys-php-binary-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

PhpBinaryParser
===============

[](#phpbinaryparser)

A lightweight PHP library for parsing binary data from byte arrays. Supports signed and unsigned integers, arrays, and endian-aware formats (big/little endian). Ideal for reading hardware data streams, binary protocols, or any low-level byte-oriented data.

Features
--------

[](#features)

- Supports 8, 16, 24, 32, and 64-bit integers
- Signed and unsigned parsing
- Little-endian and big-endian support
- **Bytes are consumed from the buffer after each read**
- Multi-read support (`readMany()`)
- Resettable buffer with `resetBuffer()`
- Type-safe with meaningful exceptions

Installation
------------

[](#installation)

You can install via Composer:

```
composer require pigeonboys/php-binary-parser
```

PHP version 8.0+ is required.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use PigeonBoys\PhpBinaryParser\BinaryParser;

$buffer = [0x12, 0x34, 0x56, 0x78];
$parser = new BinaryParser($buffer);

// Read an unsigned 16-bit integer in big-endian
$value = $parser->int16()->unsigned()->bigEndian()->read();
echo $value; // 4660

// After this read, the first two bytes are removed from the buffer
echo $parser->bytesRemaining(); // 2
```

### Reading Multiple Values

[](#reading-multiple-values)

```
$parser = new BinaryParser([0x01, 0x02, 0x03, 0x04]);

// Read two unsigned 8-bit integers
$values = $parser->int8()->unsigned()->readMany(2);
print_r($values); // [1, 2]

// Only remaining bytes are left in the buffer
echo $parser->bytesRemaining(); // 2
```

### Resetting Buffer

[](#resetting-buffer)

```
$parser->resetBuffer(); // restores all original bytes
```

Methods
-------

[](#methods)

- `int8()`, `int16()`, `int24()`, `int32()`, `int64()` — *Set the bitness*
- `signed()`, `unsigned()` — *Set the signedness*
- `littleEndian()`, `bigEndian()` — *Set the endianness*
- `read()` — *Read a single value and consume bytes from the buffer*
- `readMany(int $count)` — *Read multiple values and consume bytes from the buffer*
- `resetBuffer()` — *Reset buffer to original content*
- `bytesRemaining()` — *Get the number of bytes left*

Exceptions
----------

[](#exceptions)

- `BitnessAlreadySetException` — *Thrown if you try to set the bitness more than once before reading.*
- `EndiannessAlreadySetException` — *Thrown if you try to set the endianness more than once before reading.*
- `SignednessAlreadySetException` — *Thrown if you try to set signedness more than once before reading.*
- `BitnessNotSetException` — *Thrown if you attempt to read an integer without first specifying the bitness.*
- `EndiannessNotSetException` — *Thrown if you attempt to read a multi-byte integer without specifying endianness (except 8-bit).*
- `SignednessNotSetException` — *Thrown if you attempt to read an integer without specifying signed or unsigned.*
- `InvalidLengthException` — *Thrown if the number of bytes requested for `readBytes()` is less than 1.*
- `InvalidCountException` — *Thrown if `readMany()` is called with a count less than 1.*
- `CurrentBufferUnderflowException` — *Thrown if there are not enough bytes left in the buffer to satisfy a read.*

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance59

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

259d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9717457d8c22f77abd366048d290b3b63eec1258ee971817c456f7fc06123f06?d=identicon)[nicestdev](/maintainers/nicestdev)

---

Top Contributors

[![nicestdev](https://avatars.githubusercontent.com/u/66088868?v=4)](https://github.com/nicestdev "nicestdev (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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